public void ElGamalDec1() { ElGamal algorithm = new ElGamal(); int plain = algorithm.Decrypt(2781, 437, 191, 7187); Assert.AreEqual(plain, 19); }
public void ElGamalDec2() { ElGamal algorithm = new ElGamal(); int plain = algorithm.Decrypt(6066, 899, 118, 6323); Assert.AreEqual(plain, 111); }
public bool TryDecryptSessionInfo(ReadOnlySpan <byte> encryptedSessionData, Span <byte> sessionData, out int bytesWritten) { var g = MPInteger.ReadInteger(encryptedSessionData, out var gBytesRead); var p = MPInteger.ReadInteger(encryptedSessionData.Slice(gBytesRead), out var _); var halfLength = Math.Max(g.Length, p.Length); var inputData = new byte[halfLength * 2]; g.CopyTo(inputData.AsSpan(halfLength - g.Length)); p.CopyTo(inputData.AsSpan(inputData.Length - p.Length)); var data = elGamal.Decrypt(inputData, RSAEncryptionPadding.Pkcs1); if (sessionData.Length >= data.Length) { data.CopyTo(sessionData); bytesWritten = data.Length; return(true); } bytesWritten = 0; return(false); }