示例#1
0
        protected RSAPKCS1Algorithm(string hashAlgorithm, CryptographicKey publicKey = null, CryptographicKey privateKey = null)
            : this(hashAlgorithm)
        {
            this.disposePublicKey = true;
            this.disposePrivateKey = true;

            if (publicKey != null)
            {
                this.publicKey = GetAlgorithmFromCryptographicKey(publicKey);

                if (this.publicKey.KeySize < 2048)
                {
                    this.Dispose();
                    throw new ArgumentException("Key size must be at 2048bits");
                }
            }

            if (privateKey != null)
            {
                this.privateKey = GetAlgorithmFromCryptographicKey(privateKey);

                if (this.privateKey.KeySize < 2048)
                {
                    this.Dispose();
                    throw new ArgumentException("Key size must be at 2048bits");
                }
            }
        }
示例#2
0
 public override void SetKey(CryptographicKey key)
 {
     throw new NotImplementedException();
 }
示例#3
0
 public RS512Algorithm(CryptographicKey publicKey = null, CryptographicKey privateKey = null)
     : base("SHA512", publicKey, privateKey)
 {
 }
示例#4
0
 public override void SetKey(CryptographicKey key)
 {
     base.SetKey(key);
 }
示例#5
0
 public RS256Algorithm(CryptographicKey publicKey = null, CryptographicKey privateKey = null)
     : base("SHA256", publicKey, privateKey)
 {
 }
示例#6
0
 public HS384Algorithm(CryptographicKey key)
     : this(GetKey(key))
 {
 }
示例#7
0
        /// <summary>
        /// Create a public AsymmetricAlgorithm from CryptographicKey
        /// </summary>
        /// <param name="key"></param>
        public virtual void SetKey(CryptographicKey key)
        {
            this.disposePublicKey = true;

            if (key.X509CertificateChain.Count() > 0)
            {
                // check x509 thumbprint
            }
            else if (key.X509Url != null)
            {
                // check x509 thumbprint
            }
            else
            {
                this.publicKey = GetAlgorithmFromCryptographicKey(key);
            }
        }
示例#8
0
        private static AsymmetricAlgorithm GetAlgorithmFromCryptographicKey(CryptographicKey key)
        {
            RSAParameters rsaParameters = default(RSAParameters);

            key.TryGetValue("e", out rsaParameters.Modulus);
            key.TryGetValue("n", out rsaParameters.Exponent);
            key.TryGetValue("d", out rsaParameters.D);
            key.TryGetValue("p", out rsaParameters.P);
            key.TryGetValue("q", out rsaParameters.Q);
            key.TryGetValue("dp", out rsaParameters.DP);
            key.TryGetValue("dq", out rsaParameters.DQ);

            var provider = new RSACryptoServiceProvider();
            provider.ImportParameters(rsaParameters);

            return provider;
        }
示例#9
0
 public RS384Algorithm(CryptographicKey publicKey = null, CryptographicKey privateKey = null)
     : base("SHA384", publicKey, privateKey)
 {
 }