public void EncryptAndDecrypt_AES_IV()
 {
     byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(this.aesKey, this.data, this.iv);
     CollectionAssertEx.AreNotEqual(this.data, cipherText);
     Assert.AreEqual(DataAesCiphertextBase64, Convert.ToBase64String(cipherText));
     byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(this.aesKey, cipherText, this.iv);
     CollectionAssertEx.AreEqual(this.data, plainText);
 }
 public void EncryptAndDecrypt_AES_NoIV()
 {
     byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(this.aesKey, this.data, null);
     CollectionAssertEx.AreNotEqual(this.data, cipherText);
     Assert.AreEqual("oCSAA4sUCGa5ukwSJdeKWw==", Convert.ToBase64String(cipherText));
     byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(this.aesKey, cipherText, null);
     CollectionAssertEx.AreEqual(this.data, plainText);
 }
Exemple #3
0
        public void GetBytes()
        {
            byte[] keyFromPassword = NetFxCrypto.DeriveBytes.GetBytes(Password1, Salt1, 5, 10);
            byte[] keyFromBytes    = NetFxCrypto.DeriveBytes.GetBytes(Encoding.UTF8.GetBytes(Password1), Salt1, 5, 10);
            CollectionAssertEx.AreEqual(keyFromPassword, keyFromBytes);
            Assert.AreEqual(DerivedKey, Convert.ToBase64String(keyFromPassword));

            byte[] keyWithOtherSalt = NetFxCrypto.DeriveBytes.GetBytes(Password1, Salt2, 5, 10);
            CollectionAssertEx.AreNotEqual(keyFromPassword, keyWithOtherSalt);
        }
        public void GenerateRandom()
        {
            byte[] buffer1 = WinRTCrypto.CryptographicBuffer.GenerateRandom(15);
            Assert.AreEqual(15, buffer1.Length);

            byte[] buffer2 = WinRTCrypto.CryptographicBuffer.GenerateRandom(15);
            Assert.AreEqual(15, buffer2.Length);

            CollectionAssertEx.AreNotEqual(buffer1, buffer2);
        }
 public void EncryptAndDecrypt_RSA()
 {
     byte[] keyMaterialBytes = Convert.FromBase64String(AesKeyMaterial);
     byte[] cipherText       = WinRTCrypto.CryptographicEngine.Encrypt(
         this.rsaEncryptingKey,
         keyMaterialBytes,
         null);
     CollectionAssertEx.AreNotEqual(keyMaterialBytes, cipherText);
     byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(this.rsaEncryptingKey, cipherText, null);
     CollectionAssertEx.AreEqual(keyMaterialBytes, plainText);
 }