Exemple #1
0
        /// <summary>
        /// Decrypts the data of the IEncryptable with the key and sets the IV for future decryption
        /// </summary>
        /// <param name="keyMaterial">The AES encryption key</param>
        /// <param name="encryptable">The object to be decrypted, containing encrypted data (ciphertext)</param>
        /// <returns>The object with decrypted data (plaintext)</returns>
        private static IEncryptable DecryptData(byte[] keyMaterial, IEncryptable encryptable)
        {
            var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
            var key      = provider.CreateSymmetricKey(keyMaterial);

            var plainText = WinRTCrypto.CryptographicEngine.Decrypt(key, encryptable.GetData(), encryptable.GetIV());

            encryptable.SetData(plainText);

            return(encryptable);
        }
Exemple #2
0
        /// <summary>
        /// Encrypts the data of the IEncryptable with the key and sets the IV for future decryption
        /// </summary>
        /// <param name="keyMaterial">The AES encryption key</param>
        /// <param name="encryptable">The object to be encrypted, containing not encrypted data (plaintext)</param>
        /// <returns>The object with encrypted data (ciphertext)</returns>
        private static IEncryptable EncryptData(byte[] keyMaterial, IEncryptable encryptable)
        {
            var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
            var key      = provider.CreateSymmetricKey(keyMaterial);

            var iv         = WinRTCrypto.CryptographicBuffer.GenerateRandom(provider.BlockLength);
            var cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key, encryptable.GetData(), iv);

            encryptable.SetData(cipherText);
            encryptable.SetIV(iv);

            return(encryptable);
        }