Ejemplo n.º 1
0
 public void EncryptAndDecrypt_AES_NoIV()
 {
     byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(this.aesKey, this.data, null);
     CollectionAssertEx.AreNotEqual(this.data, cipherText);
     Assert.Equal("oCSAA4sUCGa5ukwSJdeKWw==", Convert.ToBase64String(cipherText));
     byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(this.aesKey, cipherText, null);
     CollectionAssertEx.AreEqual(this.data, plainText);
 }
Ejemplo n.º 2
0
    public void GenerateRandom()
    {
        byte[] buffer1 = WinRTCrypto.CryptographicBuffer.GenerateRandom(15);
        Assert.Equal(15, buffer1.Length);

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

        CollectionAssertEx.AreNotEqual(buffer1, buffer2);
    }
    public void GetBytes()
    {
        byte[] keyFromPassword = NetFxCrypto.DeriveBytes.GetBytes(Password1, Salt1, 5, 10, HashAlgorithmName.SHA1);
        byte[] keyFromBytes    = NetFxCrypto.DeriveBytes.GetBytes(Encoding.UTF8.GetBytes(Password1), Salt1, 5, 10, HashAlgorithmName.SHA1);
        CollectionAssertEx.AreEqual(keyFromPassword, keyFromBytes);
        Assert.Equal(DerivedKey, Convert.ToBase64String(keyFromPassword));

        byte[] keyWithOtherSalt = NetFxCrypto.DeriveBytes.GetBytes(Password1, Salt2, 5, 10, HashAlgorithmName.SHA1);
        CollectionAssertEx.AreNotEqual(keyFromPassword, keyWithOtherSalt);
    }
Ejemplo n.º 4
0
 public void EncryptAndDecrypt_RSA()
 {
     byte[] keyMaterialBytes = Convert.FromBase64String(AesKeyMaterial);
     byte[] cipherText       = WinRTCrypto.CryptographicEngine.Encrypt(
         RsaEncryptingKey,
         keyMaterialBytes,
         null);
     CollectionAssertEx.AreNotEqual(keyMaterialBytes, cipherText);
     byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(RsaEncryptingKey, cipherText, null);
     CollectionAssertEx.AreEqual(keyMaterialBytes, plainText);
 }
Ejemplo n.º 5
0
    public void EncryptAndDecrypt_AES_IV()
    {
        byte[] iv         = IV;
        byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(this.aesKey, this.data, iv);
        CollectionAssertEx.AreNotEqual(this.data, cipherText);
        Assert.Equal(DataAesCiphertextBase64, Convert.ToBase64String(cipherText));
        Assert.Equal <byte>(iv, IV); // ensure IV wasn't tampered with

        byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(this.aesKey, cipherText, iv);
        CollectionAssertEx.AreEqual(this.data, plainText);
        Assert.Equal <byte>(iv, IV); // ensure IV wasn't tampered with
    }