/// <summary>Constructor</summary>
        /// <param name="xmlKey">string</param>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignXML(string xmlKey, EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;

            if (aa is RSA)
            {
                RSA rsa = (RSA)aa;
                rsa.FromXmlString(xmlKey);
                this.AsymmetricAlgorithm = rsa;
            }
            else if (aa is DSA)
            {
                DSA dsa = (DSA)aa;
                dsa.FromXmlString(xmlKey);
                this.AsymmetricAlgorithm = dsa;
            }
            else
            {
                throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
            }
        }
 /// <summary>Constructor</summary>
 /// <param name="algorithm">EnumASymmetricAlgorithm</param>
 /// <param name="certificateFilePath">X.509証明書(*.pfx, *.cer)へのパス</param>
 /// <param name="password">パスワード</param>
 /// <param name="flag">X509KeyStorageFlags</param>
 public ASymmetricCryptography(EnumASymmetricAlgorithm algorithm,
                               string certificateFilePath = "", string password = "",
                               X509KeyStorageFlags flag   = X509KeyStorageFlags.DefaultKeySet)
 {
     this._asa = AsymmetricAlgorithmCmnFunc.CreateCryptographySP(
         algorithm, certificateFilePath, password, flag);
 }
        /// <summary>Constructor</summary>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignXML(EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;
        }
        /// <summary>Constructor</summary>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        /// <param name="hashAlgorithm">HashAlgorithm</param>
        public DigitalSignECDsaOpenSsl(EnumDigitalSignAlgorithm eaa, HashAlgorithm hashAlgorithm)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            ECDsaOpenSsl ecdsa = (ECDsaOpenSsl)aa;

            this._privateKey = ecdsa.ExportParameters(true);
            this._publicKey  = ecdsa.ExportParameters(false);

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = hashAlgorithm;
        }
Exemple #5
0
        /// <summary>Constructor</summary>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignECDsaCng(EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            ECDsaCng ecdsa = (ECDsaCng)aa;

            this._privateKey = ecdsa.Key;
            this._publicKey  = this._privateKey.Export(CngKeyBlobFormat.EccPublicBlob);

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;
        }
        /// <summary>Constructor</summary>
        /// <param name="dsaParameters">DSAParameters</param>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignParam(DSAParameters dsaParameters, EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            if (aa is DSA)
            {
                ((DSA)aa).ImportParameters(dsaParameters);
            }
            else
            {
                throw new ArgumentException("unmatched");
            }

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;
        }
        /// <summary>準備</summary>
        private void Prepare()
        {
            AsymmetricAlgorithm aa = null;

            if (this.X509Certificate.PrivateKey == null)
            {
                // *.cer
                aa = this.GetPublicKey();
            }
            else
            {
                // *.pfx
                aa = this.GetPrivateKey();

                // *.pfxの場合、ExportParameters(true)して生成し直す必要がある。
                if (aa is RSA)
                {
                    // RSA
                    RSA rsa = (RSA)AsymmetricAlgorithmCmnFunc.CreateSameKeySizeSP(aa);
                    rsa.ImportParameters(((RSA)(aa)).ExportParameters(true));
                    aa = rsa;
                }
                else if (aa is DSA)
                {
                    // DSA
                    DSA dsa = (DSA)AsymmetricAlgorithmCmnFunc.CreateSameKeySizeSP(aa);
                    dsa.ImportParameters(((DSA)(aa)).ExportParameters(true));
                    aa = dsa;
                }
                else
                {
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }

            // AsymmetricAlgorithmを設定
            this.AsymmetricAlgorithm = aa;
        }
        /// <summary>Constructor</summary>
        /// <param name="rsaParameters">RSAParameters</param>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignParam(RSAParameters rsaParameters, EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            if (aa is RSA)
            {
                RSAParameters temp = new RSAParameters()
                {
                    // Public
                    Modulus  = rsaParameters.Modulus,
                    Exponent = rsaParameters.Exponent,
                };

                if (rsaParameters.D != null &&
                    rsaParameters.D.Length != 0)
                {
                    // Private
                    temp.D        = rsaParameters.D;
                    temp.P        = rsaParameters.P;
                    temp.Q        = rsaParameters.Q;
                    temp.DP       = rsaParameters.DP;
                    temp.DQ       = rsaParameters.DQ;
                    temp.InverseQ = rsaParameters.InverseQ;
                }

                ((RSA)aa).ImportParameters(temp);
            }
            else
            {
                throw new ArgumentException("unmatched");
            }

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;
        }