Example #1
0
        /// <summary>
        /// Get the RSA crypto service provider for the CA public key.
        /// </summary>
        /// <param name="publicKey">The stream containing the public key data.</param>
        /// <param name="password">The password used to decrypt the key within the file.</param>
        /// <returns>The RSA cryto service provider with the public key.</returns>
        public RSACryptoServiceProvider PublicKeyProvider(StreamReader publicKey, string password = null)
        {
            Key.OpenSsl.PemReader publicKeyReader = null;

            if (String.IsNullOrEmpty(password))
            {
                // Read the public key file.
                publicKeyReader = new Key.OpenSsl.PemReader(publicKey);
            }
            else
            {
                // Read the public key file.
                publicKeyReader = new Key.OpenSsl.PemReader(publicKey, new PasswordFinder(password));
            }

            // Get the ras key parameters
            Cryptography.Key.X509.X509Certificate x509Certificate = (Cryptography.Key.X509.X509Certificate)publicKeyReader.ReadObject();

            // Get the ras key parameters
            Cryptography.Key.Crypto.Parameters.RsaKeyParameters rsaPublicKey = (Cryptography.Key.Crypto.Parameters.RsaKeyParameters)x509Certificate.GetPublicKey();

            // Assign the rsa parameters.
            RSAParameters rsaPublicParam = new RSAParameters();

            rsaPublicParam.Exponent = rsaPublicKey.Exponent.ToByteArrayUnsigned();
            rsaPublicParam.Modulus  = rsaPublicKey.Modulus.ToByteArrayUnsigned();

            // Create the encyption provider.
            RSACryptoServiceProvider rsaEncryptProvider = new RSACryptoServiceProvider();

            rsaEncryptProvider.ImportParameters(rsaPublicParam);

            // Return the rsa provider.
            return(rsaEncryptProvider);
        }
Example #2
0
        /// <summary>
        /// Online certificate status protocol responder.
        /// </summary>
        /// <param name="signerPublicKey">The signing public key parameters (The certificate to sign OCSP responses with : can be the Certificate Authority Public Key).</param>
        /// <param name="certificateAuthorityPublicKey">The certificate authority public key parameters (Corresponding to the revocation information in index file).</param>
        /// <param name="certificateAuthorityPrivateKey">The certificate authority private key parameters (The private key to sign OCSP responses with).</param>
        public Responder(RSAParameters signerPublicKey, RSAParameters certificateAuthorityPublicKey, RSAParameters certificateAuthorityPrivateKey)
        {
            _publicKeyCA =
                new Cryptography.Key.Crypto.Parameters.RsaKeyParameters(false,
                                                                        new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPublicKey.Modulus),
                                                                        new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPublicKey.Exponent));

            _publicKeySig =
                new Cryptography.Key.Crypto.Parameters.RsaKeyParameters(false,
                                                                        new Cryptography.Key.Math.BigInteger(1, signerPublicKey.Modulus),
                                                                        new Cryptography.Key.Math.BigInteger(1, signerPublicKey.Exponent));

            _privateKeyCA =
                new Cryptography.Key.Crypto.Parameters.RsaPrivateCrtKeyParameters(
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.Modulus),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.Exponent),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.D),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.P),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.Q),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.DP),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.DQ),
                    new Cryptography.Key.Math.BigInteger(1, certificateAuthorityPrivateKey.InverseQ));
        }