Ejemplo n.º 1
0
        public void TestEcdsaSignAndVerify(ushort ecOpensslNid)
        {
            var digest     = DoSha256Digest(Encoding.UTF8.GetBytes("PascalCoin"));
            var privateKey = GetNewPrivateKey(ecOpensslNid);
            var sig        = DoEcdsaSign(privateKey, digest);

            Assert.IsTrue(ECCrypto.ECDSAVerify(privateKey.PublicKey, digest, sig));
        }
Ejemplo n.º 2
0
        public void TestEncodeAndDecodeSig(ushort ecOpensslNid)
        {
            var origSig = DoEcdsaSign(GetNewPrivateKey(ecOpensslNid),
                                      DoSha256Digest(Encoding.UTF8.GetBytes("PascalCoin")));
            var encodeSig = ECCrypto.EncodeSignature(origSig);

            _ = ECCrypto.DecodeSignature(encodeSig, out var newSig);
            Assert.IsTrue(AreEcdsaSigEqual(origSig, newSig));
        }
Ejemplo n.º 3
0
        public void TestPascalCoinAesEncryptAndDecrypt(byte[] message, byte[] password)
        {
            var decryptedMessage = Array.Empty <byte>();
            var isDecrypted      =
                ECCrypto.DoPascalCoinAESDecrypt(ECCrypto.DoPascalCoinAESEncrypt(message, password),
                                                password, ref decryptedMessage);

            Assert.IsTrue(isDecrypted);
            Assert.IsTrue(message.SequenceEqual(decryptedMessage));
        }
Ejemplo n.º 4
0
        public void TestPascalCoinEciesEncryptAndDecrypt(ushort ecOpensslNid, byte[] message)
        {
            var encryptedMessage = Array.Empty <byte>();
            var decryptedMessage = Array.Empty <byte>();
            var privateKey       = GetNewPrivateKey(ecOpensslNid);
            var publicKey        = privateKey.PublicKey;
            var isEncrypted      = ECCrypto.DoPascalCoinECIESEncrypt(publicKey, message, ref encryptedMessage);

            Assert.IsTrue(isEncrypted);
            var isDecrypted = ECCrypto.DoPascalCoinECIESDecrypt(privateKey.EC_OpenSSL_NID,
                                                                privateKey.PrivateKey.RAW_PrivKey, encryptedMessage, ref decryptedMessage);

            Assert.IsTrue(isDecrypted);
            Assert.IsTrue(message.SequenceEqual(decryptedMessage));
        }
Ejemplo n.º 5
0
 public void TestIsHumanReadable(byte[] bytesToParse, bool pass) =>
 Assert.AreEqual(ECCrypto.IsHumanReadable(bytesToParse), pass);
Ejemplo n.º 6
0
 public void TestEncodeAndDecodeHexString(string stringToParse) =>
 Assert.AreEqual(ECCrypto.RawToHex(ECCrypto.HexaToRaw(stringToParse)).ToUpperInvariant(), stringToParse.ToUpperInvariant());
Ejemplo n.º 7
0
 public void TestHexString(string stringToParse, bool pass) =>
 Assert.AreEqual(ECCrypto.IsHexString(stringToParse), pass);
        protected override void InitActions()
        {
            IConnectionCrypto Crypto = new ECCrypto(true);

            Connection.InitializeCrypto(Crypto);
        }
Ejemplo n.º 9
0
 private static byte[] DoSha256Digest(byte[] message) => ECCrypto.DoSha256(message);
Ejemplo n.º 10
0
 private static ECDSA_SIG DoEcdsaSign(ECPrivateKey privateKey, byte[] digest) =>
 ECCrypto.ECDSASign(privateKey.PrivateKey, digest);