public static string Decrypt(X509Certificate2 privateKey, EncryptedPayload payload)
        {
            byte [] decryptedKey = X509Encryption.Decrypt(privateKey, payload.Key);

            string retVal = AESEncryption.Decrypt(decryptedKey, Convert.FromBase64String(payload.Salt), payload.Data);

            return(retVal);
        }
        public DigitalSignature Sign(string DATA_TO_ENCRYPT = "How are you")
        {
            // Encrypt with the certificate and decrypt with the combo pfx
            var signature = DigitalSignature.BuildSignedMessage(new X509Certificate2(_senderPrivatePublicPath), new X509Certificate2(_recieverPublicPath), DATA_TO_ENCRYPT);

            var untampered = X509Encryption.VerifySignature(new X509Certificate2(_senderPrivatePublicPath), signature.Cipher, signature.Signature);

            Assert.IsTrue(untampered);

            return(signature);
        }
示例#3
0
        public void LoadCertificateFromStore()
        {
            var cert = X509Encryption.LoadCertificate(StoreLocation.LocalMachine, "CN=ByronChild");

            String data = "Helojnmj kuhkjh ii";

            var encrypted = X509Encryption.Encrypt(cert, data);

            var decrypted = X509Encryption.DecryptAsString(cert, encrypted);

            Assert.AreEqual(data, decrypted, false);
        }
        public static EncryptedPayload Encrypt(X509Certificate2 publicCert, String target)
        {
            byte[] key           = AESEncryption.CreateKey();
            string encryptedData = AESEncryption.EncryptToString(target, key, out byte[] salt);
            string encryptedKey  = X509Encryption.Encrypt(publicCert, key);

            return(new EncryptedPayload()
            {
                Data = encryptedData,
                Key = encryptedKey,
                Salt = Convert.ToBase64String(salt)
            });
        }
        public void Decrypt()
        {
            const string target = "What the hell .. How are you";

            var result = Sign(target);

            var untampered = X509Encryption.VerifySignature(new X509Certificate2(_senderPrivatePublicPath), result.Cipher, result.Signature);

            Assert.IsTrue(untampered);

            string decrypted = X509Encryption.DecryptAsString(new X509Certificate2(_recieverPrivatePublicPath), result.Cipher);

            Assert.AreEqual(target, decrypted, false);
        }
示例#6
0
        public void PublicPrivateKeyFromFile()
        {
            string DATA_TO_ENCRYPT = "How are you";

            // Encrypt with the certificate and decrypt with the combo pfx
            X509Certificate2 publicX509    = new X509Certificate2(_certificatePath);
            String           encryptedData = X509Encryption.Encrypt(publicX509, DATA_TO_ENCRYPT);

            X509Certificate2 comboKey      = new X509Certificate2(_public_private_package_path);
            String           decryptedData = X509Encryption.DecryptAsString(comboKey, encryptedData);

            Assert.AreEqual(DATA_TO_ENCRYPT, decryptedData, false, "Strings don't match");


            // Encrypt with the combo and decrypt with the combo pfx
            encryptedData = X509Encryption.Encrypt(comboKey, DATA_TO_ENCRYPT);
            decryptedData = X509Encryption.DecryptAsString(comboKey, encryptedData);
            Assert.AreEqual(DATA_TO_ENCRYPT, decryptedData, false, "Strings don't match");
        }