Ejemplo n.º 1
0
        public byte[] EncryptSessionInfo(ReadOnlySpan <byte> sessionInfo)
        {
            var encryptedSessionInfo = rsa.Encrypt(sessionInfo.ToArray(), RSAEncryptionPadding.Pkcs1);
            var mp = new byte[MPInteger.GetMPEncodedLength(encryptedSessionInfo)];

            MPInteger.TryWriteInteger(encryptedSessionInfo, mp, out var _);
            return(mp);
        }
Ejemplo n.º 2
0
        public byte[] CreateSignature(
            ReadOnlySpan <byte> rgbHash,
            PgpHashAlgorithm hashAlgorithm)
        {
            var signature      = rsa.SignHash(rgbHash.ToArray(), PgpUtilities.GetHashAlgorithmName(hashAlgorithm), RSASignaturePadding.Pkcs1);
            var signatureBytes = new byte[MPInteger.GetMPEncodedLength(signature)];

            MPInteger.TryWriteInteger(signature, signatureBytes, out var _);
            return(signatureBytes);
        }
Ejemplo n.º 3
0
        public byte[] CreateSignature(ReadOnlySpan <byte> rgbHash, PgpHashAlgorithm hashAlgorithm)
        {
            byte[] ieeeSignature = dsa.CreateSignature(rgbHash.ToArray(), DSASignatureFormat.IeeeP1363FixedFieldConcatenation);
            var    r             = ieeeSignature.AsSpan(0, ieeeSignature.Length / 2);
            var    s             = ieeeSignature.AsSpan(ieeeSignature.Length / 2);

            byte[] pgpSignature = new byte[MPInteger.GetMPEncodedLength(r) + MPInteger.GetMPEncodedLength(s)];
            MPInteger.TryWriteInteger(r, pgpSignature, out int rWritten);
            MPInteger.TryWriteInteger(s, pgpSignature.AsSpan(rWritten), out int _);
            return(pgpSignature);
        }
Ejemplo n.º 4
0
        public byte[] EncryptSessionInfo(ReadOnlySpan <byte> sessionInfo)
        {
            var encryptedData = elGamal.Encrypt(sessionInfo, RSAEncryptionPadding.Pkcs1);
            var g             = encryptedData.Slice(0, encryptedData.Length / 2);
            var p             = encryptedData.Slice(encryptedData.Length / 2);
            var mp            = new byte[MPInteger.GetMPEncodedLength(g) + MPInteger.GetMPEncodedLength(p)];

            MPInteger.TryWriteInteger(g, mp, out var gWritten);
            MPInteger.TryWriteInteger(p, mp.AsSpan(gWritten), out var _);
            return(mp);
        }