コード例 #1
0
ファイル: Interop.Rsa.cs プロジェクト: johnhhm/corefx
        internal static unsafe RSAParameters ExportRsaParameters(SafeRsaHandle key, bool includePrivateParameters)
        {
            Debug.Assert(
                key != null && !key.IsInvalid,
                "Callers should check the key is invalid and throw an exception with a message");

            if (key == null || key.IsInvalid)
            {
                throw new CryptographicException();
            }

            RSAParameters rsaParameters;
            bool addedRef = false;

            try
            {
                key.DangerousAddRef(ref addedRef);
                RSA_ST* rsaStructure = (RSA_ST*)key.DangerousGetHandle();

                int modulusSize = RSA_size(key);

                // RSACryptoServiceProvider expects P, DP, Q, DQ, and InverseQ to all
                // be padded up to half the modulus size.
                int halfModulus = modulusSize / 2;

                rsaParameters = new RSAParameters
                {
                    Modulus = ExtractBignum(rsaStructure->n, modulusSize),
                    Exponent = ExtractBignum(rsaStructure->e, 0),
                };

                if (includePrivateParameters)
                {
                    rsaParameters.D = ExtractBignum(rsaStructure->d, modulusSize);
                    rsaParameters.P = ExtractBignum(rsaStructure->p, halfModulus);
                    rsaParameters.DP = ExtractBignum(rsaStructure->dmp1, halfModulus);
                    rsaParameters.Q = ExtractBignum(rsaStructure->q, halfModulus);
                    rsaParameters.DQ = ExtractBignum(rsaStructure->dmq1, halfModulus);
                    rsaParameters.InverseQ = ExtractBignum(rsaStructure->iqmp, halfModulus);
                }
            }
            finally
            {
                if (addedRef)
                {
                    key.DangerousRelease();
                }
            }

            return rsaParameters;
        }
コード例 #2
0
ファイル: SafeRsaHandle.Unix.cs プロジェクト: Czapek83/corefx
        internal static SafeRsaHandle DuplicateHandle(IntPtr handle)
        {
            Debug.Assert(handle != IntPtr.Zero);

            // Reliability: Allocate the SafeHandle before calling RSA_up_ref so
            // that we don't lose a tracked reference in low-memory situations.
            SafeRsaHandle safeHandle = new SafeRsaHandle();

            if (!Interop.Crypto.RsaUpRef(handle))
            {
                throw Interop.Crypto.CreateOpenSslCryptographicException();
            }

            safeHandle.SetHandle(handle);
            return safeHandle;
        }
コード例 #3
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
        internal static RSAParameters ExportRsaParameters(SafeRsaHandle key, bool includePrivateParameters)
        {
            Debug.Assert(
                key != null && !key.IsInvalid,
                "Callers should check the key is invalid and throw an exception with a message");

            if (key == null || key.IsInvalid)
            {
                throw new CryptographicException();
            }

            IntPtr n, e, d, p, dmp1, q, dmq1, iqmp;
            if (!GetRsaParameters(key, out n, out e, out d, out p, out dmp1, out q, out dmq1, out iqmp))
            {
                throw new CryptographicException();
            }

            int modulusSize = Crypto.RsaSize(key);

            // RSACryptoServiceProvider expects P, DP, Q, DQ, and InverseQ to all
            // be padded up to half the modulus size.
            int halfModulus = modulusSize / 2;

            RSAParameters rsaParameters = new RSAParameters
            {
                Modulus = Crypto.ExtractBignum(n, modulusSize),
                Exponent = Crypto.ExtractBignum(e, 0),
            };

            if (includePrivateParameters)
            {
                rsaParameters.D = Crypto.ExtractBignum(d, modulusSize);
                rsaParameters.P = Crypto.ExtractBignum(p, halfModulus);
                rsaParameters.DP = Crypto.ExtractBignum(dmp1, halfModulus);
                rsaParameters.Q = Crypto.ExtractBignum(q, halfModulus);
                rsaParameters.DQ = Crypto.ExtractBignum(dmq1, halfModulus);
                rsaParameters.InverseQ = Crypto.ExtractBignum(iqmp, halfModulus);
            }

            return rsaParameters;
        }
コード例 #4
0
ファイル: Interop.Rsa.cs プロジェクト: johnhhm/corefx
 internal static extern int RSA_generate_key_ex(SafeRsaHandle rsa, int bits, SafeBignumHandle e, IntPtr zero);
コード例 #5
0
ファイル: Interop.Rsa.cs プロジェクト: johnhhm/corefx
 internal static extern int RSA_size(SafeRsaHandle rsa);
コード例 #6
0
ファイル: Interop.Rsa.cs プロジェクト: johnhhm/corefx
 internal extern static int RSA_private_decrypt(int flen, byte[] from, byte[] to, SafeRsaHandle rsa, OpenSslRsaPadding padding);
コード例 #7
0
 internal static extern bool EVP_PKEY_set1_RSA(SafeEvpPKeyHandle pkey, SafeRsaHandle rsa);
コード例 #8
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
 private static extern bool GetRsaParameters(
     SafeRsaHandle key,
     out IntPtr n,
     out IntPtr e,
     out IntPtr d,
     out IntPtr p,
     out IntPtr dmp1,
     out IntPtr q,
     out IntPtr dmq1,
     out IntPtr iqmp);
コード例 #9
0
ファイル: Interop.Rsa.cs プロジェクト: jmhardison/corefx
 internal static extern bool RSA_sign(int type, byte[] m, int m_len, byte[] sigret, out int siglen, SafeRsaHandle rsa);
コード例 #10
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
 internal static extern int RsaGenerateKeyEx(SafeRsaHandle rsa, int bits, SafeBignumHandle e);
コード例 #11
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
 internal static extern int RsaSize(SafeRsaHandle rsa);
コード例 #12
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
 internal extern static int RsaPrivateDecrypt(
     int flen,
     byte[] from,
     byte[] to,
     SafeRsaHandle rsa,
     RsaPadding padding);
コード例 #13
0
ファイル: Interop.Rsa.cs プロジェクト: noahfalk/corefx
 internal static extern void SetRsaParameters(
     SafeRsaHandle key,
     byte[] n,
     int nLength,
     byte[] e,
     int eLength,
     byte[] d,
     int dLength,
     byte[] p,
     int pLength,
     byte[] dmp1,
     int dmp1Length,
     byte[] q,
     int qLength,
     byte[] dmq1,
     int dmq1Length,
     byte[] iqmp,
     int iqmpLength);
コード例 #14
0
 internal static extern bool EvpPkeySetRsa(SafeEvpPKeyHandle pkey, SafeRsaHandle rsa);
コード例 #15
0
ファイル: Interop.Rsa.cs プロジェクト: jmhardison/corefx
 internal static extern bool RSA_verify(int type, byte[] m, int m_len, byte[] sigbuf, int siglen, SafeRsaHandle rsa);
コード例 #16
0
ファイル: RSAOpenSsl.cs プロジェクト: GitTorre/corefx
 private static void CheckInvalidKey(SafeRsaHandle key)
 {
     if (key == null || key.IsInvalid)
     {
         throw new CryptographicException(SR.Cryptography_OpenInvalidHandle);
     }
 }
コード例 #17
0
ファイル: RsaOpenSsl.cs プロジェクト: niaomingjian/corefx
 private static void CheckInvalidNewKey(SafeRsaHandle key)
 {
     if (key == null || key.IsInvalid)
     {
         throw CreateOpenSslException();
     }
 }