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 calgHash = X509Utils.OidToAlgId(str); this.GetKeyPair(); if (!this.CspKeyContainerInfo.RandomlyGenerated) { KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(this._parameters, KeyContainerPermissionFlags.Sign); permission.AccessEntries.Add(accessEntry); permission.Demand(); } return Utils.SignValue(this._safeKeyHandle, this._parameters.KeyNumber, 0x2400, calgHash, rgbHash); }
[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)); }
public override byte[] CreateSignature(byte[] rgbHash) { if (rgbHash == null) { throw new ArgumentNullException("rgbHash"); } if (this._strOID == null) { throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingOID")); } if (this._rsaKey == null) { throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey")); } if (!(this._rsaKey is RSACryptoServiceProvider)) { return(this._rsaKey.DecryptValue(Utils.RsaPkcs1Padding(this._rsaKey, CryptoConfig.EncodeOID(this._strOID), rgbHash))); } int algIdFromOid = X509Utils.GetAlgIdFromOid(this._strOID, OidGroup.HashAlgorithm); return(((RSACryptoServiceProvider)this._rsaKey).SignHash(rgbHash, algIdFromOid)); }
[System.Security.SecuritySafeCritical] // auto-generated public override byte[] CreateSignature(byte[] rgbHash) { if (rgbHash == null) { throw new ArgumentNullException("rgbHash"); } Contract.EndContractBlock(); if (_strOID == null) { throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingOID")); } if (_rsaKey == null) { throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey")); } // Two cases here -- if we are talking to the CSP version or if we are talking to some other RSA provider. if (_rsaKey is RSACryptoServiceProvider) { // This path is kept around for desktop compat: in case someone is using this with a hash algorithm that's known to GetAlgIdFromOid but // not from OidToHashAlgorithmName. int calgHash = X509Utils.GetAlgIdFromOid(_strOID, OidGroup.HashAlgorithm); return(((RSACryptoServiceProvider)_rsaKey).SignHash(rgbHash, calgHash)); } else if (OverridesSignHash) { HashAlgorithmName hashAlgorithmName = Utils.OidToHashAlgorithmName(_strOID); return(_rsaKey.SignHash(rgbHash, hashAlgorithmName, RSASignaturePadding.Pkcs1)); } else { // Fallback compat path for 3rd-party RSA classes that don't override SignHash() byte[] pad = Utils.RsaPkcs1Padding(_rsaKey, CryptoConfig.EncodeOID(_strOID), rgbHash); // Create the signature by applying the private key to the padded buffer we just created. return(_rsaKey.DecryptValue(pad)); } }
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); }
public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature) { if (rgbHash == null) { throw new ArgumentNullException("rgbHash"); } if (rgbSignature == null) { throw new ArgumentNullException("rgbSignature"); } int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm); if (rgbHash.Length != this._sha1.HashSize / 8) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHashSize", new object[] { "SHA1", this._sha1.HashSize / 8 })); } this.GetKeyPair(); return(Utils.VerifySign(this._safeKeyHandle, 8704, calgHash, rgbHash, rgbSignature)); }