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 ComputeAndSignHash_VerifiesComputedSignature_Pass() { Random rdm = new Random(); byte[] message = new byte[256]; byte[] signedMessage; string nativeXmlString; bool isMessageNotTamperedWith = true; rdm.NextBytes(message); using (var rsacsp = new RSACipher<RSACryptoServiceProvider>()) { signedMessage = rsacsp.ComputeAndSignHash<SHA384Cng>(message); nativeXmlString = rsacsp.ToXmlString(true); } using (var cipher = new RSACipher<RSACryptoServiceProvider>(nativeXmlString)) { isMessageNotTamperedWith = cipher.ComputeAndVerifyHash<SHA384Cng>(message, signedMessage); } Assert.IsTrue(isMessageNotTamperedWith); }
public void SignHash_VerifiesComputedSignature_Pass() { Random rdm = new Random(); byte[] message = new byte[256]; byte[] signedMessage; string nativeXmlString; bool isMessageNotTamperedWith = true; rdm.NextBytes(message); using (var rsacsp = new RSACipher<RSACryptoServiceProvider>()) { byte[] firstHash = new SHA256Managed().ComputeHash(message); signedMessage = rsacsp.SignHash(firstHash); nativeXmlString = rsacsp.ToXmlString(true); } using (var cipher = new RSACipher<RSACryptoServiceProvider>(nativeXmlString)) { byte[] n = new SHA256Managed().ComputeHash(message); isMessageNotTamperedWith = cipher.VerifyHash(n, signedMessage); } Assert.IsTrue(isMessageNotTamperedWith); }
public void RSAParameterEncryption_ExportEncryptedParameterWithPrivateKey_Pass() { string plainKey = "soonAssigned"; byte[] salt = { 1,2,3,4,5,6,7,8,9 }; string passwd = "SafeP4ssw0rd;,,:;DWAe"; string encryptedKey = ""; string decryptedKey = "laterAssigned"; byte[] IV; using (var cipher = new RSACipher<RSACryptoServiceProvider>()) { plainKey = cipher.ToXmlString(true); encryptedKey = cipher.ToEncryptedXmlString<AesManaged>(true, passwd, salt, out IV); cipher.FromEncryptedXmlString<AesManaged>(encryptedKey, passwd, salt, IV); decryptedKey = cipher.ToXmlString(true); } Assert.AreEqual(plainKey, decryptedKey); }