public void Test_Authenticate() { var aesCryptoProvider = new AesCryptoProvider { KeyStore = _keystore, PublicKeyName = "mypublickey", SigningKeyName = "myauthsecret" }; var someText = "The old grey goose jumped over the wrickety gate."; var textBytes = Encoding.UTF8.GetBytes(someText); var encryptedTest = aesCryptoProvider.Encrypt(textBytes, out _iv); Assert.NotEqual(encryptedTest, textBytes); var hash1 = aesCryptoProvider.GetSignature(encryptedTest); var decryptedText = aesCryptoProvider.Decrypt(encryptedTest, _iv, "mypublickey"); Assert.Equal(decryptedText, textBytes); var hash2 = aesCryptoProvider.GetSignature(encryptedTest); Assert.Equal(hash1, hash2); }
public void Test_Decrypt2() { var aesCryptoProvider = new AesCryptoProvider { KeyStore = _keystore, PublicKeyName = "mypublickey", SigningKeyName = "myauthsecret" }; var message = "The old grey goose jumped over the wrickety gate."; var utf8Message = System.Text.Encoding.UTF8.GetBytes(message); byte[] iv; var encryptedBytes = aesCryptoProvider.Encrypt(utf8Message, out iv); var base64message = Convert.ToBase64String(encryptedBytes); _output.WriteLine(base64message); _output.WriteLine("iv: " + Convert.ToBase64String(iv)); var base64MessageBytes = Convert.FromBase64String(base64message); var decrypted = aesCryptoProvider.Decrypt(base64MessageBytes, iv); Assert.Equal(message, System.Text.Encoding.UTF8.GetString(decrypted)); _output.WriteLine("authkey: " + Convert.ToBase64String(Encoding.UTF8.GetBytes(_keystore.GetKey("myauthsecret")))); _output.WriteLine("sig: " + Convert.ToBase64String(aesCryptoProvider.GetSignature(encryptedBytes))); }