コード例 #1
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            Contract.EndContractBlock();
            if (PublicOnly)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_NoPrivateKey"));
            }

            int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            if (rgbHash.Length != _sha1.HashSize / 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHashSize", "SHA1", _sha1.HashSize / 8));
            }

            GetKeyPair();
            if (!CspKeyContainerInfo.RandomlyGenerated)
            {
                KeyContainerPermission            kp    = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
                KeyContainerPermissionAccessEntry entry = new KeyContainerPermissionAccessEntry(_parameters, KeyContainerPermissionFlags.Sign);
                kp.AccessEntries.Add(entry);
                kp.Demand();
            }
            return(Utils.SignValue(_safeKeyHandle, _parameters.KeyNumber, Constants.CALG_DSS_SIGN, calgHash, rgbHash));
        }
コード例 #2
0
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (this.PublicOnly)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_NoPrivateKey"));
            }
            int algId = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            if (rgbHash.Length != this._sha1.HashSize / 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHashSize", (object)"SHA1", (object)(this._sha1.HashSize / 8)));
            }
            this.GetKeyPair();
            if (!this.CspKeyContainerInfo.RandomlyGenerated)
            {
                KeyContainerPermission            containerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
                KeyContainerPermissionAccessEntry accessEntry         = new KeyContainerPermissionAccessEntry(this._parameters, KeyContainerPermissionFlags.Sign);
                containerPermission.AccessEntries.Add(accessEntry);
                containerPermission.Demand();
            }
            return(Utils.SignValue(this._safeKeyHandle, this._parameters.KeyNumber, 8704, algId, rgbHash));
        }
コード例 #3
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
        {
            if (keySize < 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }

            int algidhash = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);

            if (algidhash == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }

            int algid = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);

            if (algid == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }

            // Validate the rgbIV array
            if (rgbIV == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
            }

            byte[] key = null;
            DeriveKey(ProvHandle, algid, algidhash,
                      m_password, m_password.Length, keySize << 16, rgbIV, rgbIV.Length,
                      JitHelpers.GetObjectHandleOnStack(ref key));
            return(key);
        }
コード例 #4
0
        public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
        {
            if (keySize < 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            int num = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);

            if (num == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            int num2 = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);

            if (num2 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            if (rgbIV == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
            }
            byte[] result = null;
            PasswordDeriveBytes.DeriveKey(this.ProvHandle, num2, num, this._password, this._password.Length, keySize << 16, rgbIV, rgbIV.Length, JitHelpers.GetObjectHandleOnStack <byte[]>(ref result));
            return(result);
        }
コード例 #5
0
        /// <summary>通过使用提供的公钥确定签名中的哈希值并将其与提供的哈希值进行比较来验证数字签名是否有效。</summary>
        /// <returns>如果签名有效,则为 true;否则为 false。</returns>
        /// <param name="rgbHash">带符号的数据的哈希值。</param>
        /// <param name="str">哈希算法标识符 (OID) 用于创建数据的哈希值。</param>
        /// <param name="rgbSignature">要验证的签名数据。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="rgbHash" /> 参数为 null。- 或 -<paramref name="rgbSignature" /> 参数为 null。</exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">无法获取加密服务提供程序 (CSP)。- 或 -不能验证签名。</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (rgbSignature == null)
            {
                throw new ArgumentNullException("rgbSignature");
            }
            int algId = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            return(this.VerifyHash(rgbHash, algId, rgbSignature));
        }
コード例 #6
0
        /// <summary>通过用私钥对其进行加密来计算指定哈希值的签名。</summary>
        /// <returns>指定哈希值的 <see cref="T:System.Security.Cryptography.RSA" /> 签名。</returns>
        /// <param name="rgbHash">要签名的数据的哈希值。</param>
        /// <param name="str">哈希算法标识符 (OID) 用于创建数据的哈希值。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="rgbHash" /> 参数为 null。</exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">无法获取加密服务提供程序 (CSP)。- 或 -没有私钥。</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (this.PublicOnly)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_NoPrivateKey"));
            }
            int algId = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            return(this.SignHash(rgbHash, algId));
        }
コード例 #7
0
        public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (rgbSignature == null)
            {
                throw new ArgumentNullException("rgbSignature");
            }
            Contract.EndContractBlock();

            int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            return(VerifyHash(rgbHash, calgHash, rgbSignature));
        }
コード例 #8
0
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            Contract.EndContractBlock();
            if (PublicOnly)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_NoPrivateKey"));
            }

            int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            return(SignHash(rgbHash, calgHash));
        }
コード例 #9
0
        public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (rgbSignature == null)
            {
                throw new ArgumentNullException("rgbSignature");
            }
            int algId = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            if (rgbHash.Length != this._sha1.HashSize / 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHashSize", (object)"SHA1", (object)(this._sha1.HashSize / 8)));
            }
            this.GetKeyPair();
            return(Utils.VerifySign(this._safeKeyHandle, 8704, algId, rgbHash, rgbSignature));
        }
コード例 #10
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            if (rgbSignature == null)
            {
                throw new ArgumentNullException("rgbSignature");
            }
            Contract.EndContractBlock();

            int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);

            if (rgbHash.Length != _sha1.HashSize / 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHashSize", "SHA1", _sha1.HashSize / 8));
            }

            GetKeyPair();
            return(Utils.VerifySign(_safeKeyHandle, Constants.CALG_DSS_SIGN, calgHash, rgbHash, rgbSignature));
        }
コード例 #11
0
        public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
        {
            if (keySize < 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            int algId1 = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);

            if (algId1 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            int algId2 = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);

            if (algId2 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            if (rgbIV == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
            }
            byte[]         o          = (byte[])null;
            SafeProvHandle provHandle = this.ProvHandle;
            int            algid      = algId2;
            int            algidHash  = algId1;

            byte[] password = this.m_password;
            int    length1  = this.m_password.Length;
            int    dwFlags  = keySize << 16;

            byte[] IV      = rgbIV;
            int    length2 = IV.Length;
            ObjectHandleOnStack objectHandleOnStack = JitHelpers.GetObjectHandleOnStack <byte[]>(ref o);

            Rfc2898DeriveBytes.DeriveKey(provHandle, algid, algidHash, password, length1, dwFlags, IV, length2, objectHandleOnStack);
            return(o);
        }