public void RSAHelper_Encrypt_By_Public_Decrypt_Success() { string input = "Hello, this is Shawn, I am learning about RSA by using BigInteger class"; var bytes = Encoding.UTF8.GetBytes(input); var resultBytes = RSAHelper.Encrypt(bytes, _rsaPublic); string result = Convert.ToBase64String(resultBytes); Debug.WriteLine("Encrypt by public key: "); Debug.WriteLine(result); EncDec ed = new EncDec(); string encryptedByED = ed.RSAEncrypt(_rsaPublicXml, input); Debug.WriteLine("WARNNING: Encrypt result are {0} equal between RSAHelper and EncDec class.", encryptedByED == result ? "" : " NOT ", ""); byte[] decryptBytes = RSAHelper.Decrypt(Convert.FromBase64String(result), _rsaPrivate); string resultDecrypted = Encoding.UTF8.GetString(decryptBytes, 0, decryptBytes.Length); Debug.WriteLine("Decrypt by public key: "); Debug.WriteLine(resultDecrypted); string resultED = ed.RSADecrypt(_rsaPrivateXml, encryptedByED); Assert.AreEqual(input, resultDecrypted); Assert.AreEqual(input, resultED); }
public void ED_RSA_Encrypt_Descript_Success() { var ed = new EncDec(); string input = "Hello, my name is Shaowei Lin, I am from China and now working in linsw.com."; string strEncrypt = ed.RSAEncrypt(_publicKey, input); Debug.WriteLine("Encrypt: " + strEncrypt); string strDecrypted = ed.RSADecrypt(_privateKey, strEncrypt); Debug.WriteLine("Decrypt: " + strDecrypted); Assert.AreEqual(input, strDecrypted); }