Example #1
0
        public string DecryptMessageWithKey(string privateKey, string messageData, string encryptedDecryptionKey,
                                            string hashOfMessage, out string encryptionKey)
        {
            Debug.WriteLine("encryptedPassword for AES: " + encryptedDecryptionKey);

            encryptionKey = DecryptWithKey(encryptedDecryptionKey, privateKey);

            Debug.WriteLine("Decrypted password for AES: " + encryptionKey);

            Contract.Assert(encryptionKey != string.Empty, "Encryption key is null");

            // decrypt message
            string decryptedMessage = new SymmetricCryptoProvider().DecryptWithKey(messageData, encryptionKey);

            //verify hash:
            Contract.Assert(SymmetricCryptoProvider.GetSecureHashForString(decryptedMessage) == hashOfMessage,
                            "Original hash does not equal decrypted hash!");

            return(decryptedMessage);
        }
Example #2
0
        // https://code.google.com/p/cryptico/

        public string EncryptMessageWithKey(string message, string publicKey, out string encryptedPassword,
                                            out string hashOfMessage)
        {
            // get a hash of the message
            hashOfMessage = SymmetricCryptoProvider.GetSecureHashForString(message);

            // generate a password:
            string encryptionKeyForAES = SymmetricCryptoProvider.GenerateKeyPhrase();

            Debug.WriteLine("encryptionKey for AES: " + encryptionKeyForAES);

            // encrypt the message with AES using the encryption key
            string encryptedMessage = new SymmetricCryptoProvider().EncryptWithKey(message, encryptionKeyForAES);

            // encrypt the Key:
            encryptedPassword = EncryptWithKey(encryptionKeyForAES, publicKey);
            Debug.WriteLine("encryptedPassword for AES: " + encryptedPassword);

            return(encryptedMessage);
        }