public void RSASimpleTest() { var data = new BigInteger(123456).ToByteArray(); var(publicKey, privateKey) = RSAKeyGenerator.Generate(); var sign = RSA.Crypt(data, privateKey); var decryptedData = RSA.Crypt(sign, publicKey); data.Should().BeEquivalentTo(decryptedData, options => options.WithStrictOrdering()); }
public void CanGenerateValidKey() { var keyGen = new RSAKeyGenerator(); var key = keyGen.Generate(512); var plainText = new BigInteger(123456789); var cipherText = BigInteger.ModPow(plainText, key.E, key.N); var actualPlainText = BigInteger.ModPow(cipherText, key.D, key.N); Assert.AreEqual(plainText, actualPlainText); }
public void RSAFunctionalTest() { var data = new byte[123456]; new Random().NextBytes(data); var hash = SHA512.GetHash(data); var(publicKey, privateKey) = RSAKeyGenerator.Generate(); var sign = RSA.Crypt(hash, privateKey); var decryptedHash = RSA.Crypt(sign, publicKey); hash.Should().BeEquivalentTo(decryptedHash, options => options.WithStrictOrdering()); }
public void CanEncryptDecryptMessage() { var keyGen = new RSAKeyGenerator(); var key = keyGen.Generate(512); var plainText = "the quick brown fox jumped over the lazy dog"; var data = new BigInteger(Encoding.UTF8.GetBytes(plainText)).ToByteArray(); var rsa = new RSA(key); var cipherText = rsa.Encrypt(data); var plainTextBytes = rsa.Decrypt(cipherText); var actualPlainText = Encoding.UTF8.GetString(plainTextBytes); Assert.AreEqual(plainText, actualPlainText); }