public void RSACipher_EncryptDecrypt_Pass() { string plainString = "Encrypt me via RSA"; string encryptedString; string decryptedString; using(var cipher = new RSACipher<RSACryptoServiceProvider>()) { encryptedString = cipher.EncryptToString(plainString); decryptedString = cipher.DecryptToString(encryptedString); } Assert.AreEqual(plainString, decryptedString); }
public void PassRSAParameter_ExportParameterWithoutPrivateKey_DecryptionWithPublicKeyFails() { string plainString = "Encrypt me via RSA"; string plainkey = ""; string encryptedString; string decryptedString; using (var cipher = new RSACipher<RSACryptoServiceProvider>()) { encryptedString = cipher.EncryptToString(plainString); plainkey = cipher.ToXmlString(false); } using (var cipher = new RSACipher<RSACryptoServiceProvider>(plainkey)) { decryptedString = cipher.DecryptToString(encryptedString); } Assert.AreEqual(plainString, decryptedString); }
public void PassRSAParameter_ExportEncryptedParameterWithPrivateKey_Pass() { string plainString = "Encrypt me via RSA"; byte[] salt = { 1,2,3,4,5,6,7,8,9 }; string passwd = "SafeP4ssw0rd;,,:;DWAe"; string encryptedKey = ""; string encryptedString; string decryptedString; byte[] IV; using (var cipher = new RSACipher<RSACryptoServiceProvider>(new RSACryptoServiceProvider(2048))) { encryptedString = cipher.EncryptToString(plainString); encryptedKey = cipher.ToEncryptedXmlString<AesManaged>(true, passwd, salt, out IV); } using (var cipher = new RSACipher<RSACryptoServiceProvider>(encryptedKey, passwd, salt, IV)) { decryptedString = cipher.DecryptToString(encryptedString); } Assert.AreEqual(plainString, decryptedString); }