Esempio n. 1
0
        public static ElGamalKey CreatePublic(
            ReadOnlySpan <byte> source,
            out int publicKeySize)
        {
            var elgamalParameters = ReadOpenPgpPublicKey(source, out publicKeySize);

            return(new ElGamalKey(ElGamal.Create(elgamalParameters)));
        }
Esempio n. 2
0
        public static ElGamalKey CreatePrivate(
            ReadOnlySpan <byte> password,
            ReadOnlySpan <byte> source,
            out int bytesRead)
        {
            var elgamalParameters = ReadOpenPgpPublicKey(source, out bytesRead);

            byte[] xArray = new byte[source.Length - bytesRead];

            try
            {
                S2kBasedEncryption.DecryptSecretKey(password, source.Slice(bytesRead), xArray, out int bytesWritten);
                elgamalParameters.X = MPInteger.ReadInteger(xArray, out int xConsumed).ToArray();
                bytesRead           = source.Length;
                return(new ElGamalKey(ElGamal.Create(elgamalParameters)));
            }
            finally
            {
                CryptographicOperations.ZeroMemory(xArray);
                CryptographicOperations.ZeroMemory(elgamalParameters.X);
            }
        }