/// <summary> /// Проверяет подлинность подписи для указанного значения хэш. /// </summary> /// /// <param name="rgbHash">Хэш, для которого проверяется /// подпись.</param> /// <param name="rgbSignature">Подпись, подлинность которой /// необходимо проверить.</param> /// /// <returns><see langword="true"/>, если продпись подлинна, /// <see langword="false"/> - иначе.</returns> /// /// <remarks>Алгоритм вычисления хэш для ГОСТ Р 34.10 /// всегда ГОСТ Р 34.11.</remarks> /// /// <doc-sample path="Simple\Sign" name="SignHash">Пример подписи и /// проверки подписи хэш.</doc-sample> /// /// <containerperm flag="Open">Для открытия существующего /// контейнера.</containerperm> /// <containerperm flag="Create">Для создания контейнера с заданным /// (не случаыным именем).</containerperm> public bool VerifyHash(byte[] rgbHash, byte[] rgbSignature) { if (rgbHash == null) { throw new ArgumentNullException(nameof(rgbHash)); } if (rgbSignature == null) { throw new ArgumentNullException(nameof(rgbSignature)); } if (rgbHash.Length != (GostConstants.GOST3411_SIZE / 8)) { throw new CryptographicException( string.Format( SR.Cryptography_InvalidHashSize, "GOST3411", GostConstants.GOST3411_SIZE / 8)); } GetKeyPair(); bool ret = CapiHelper.VerifySign( _safeProvHandle, _safeKeyHandle, CapiHelper.CALG_RSA_SIGN, //переворачиваем подпись, раньше (Sharpei) переворачивали только в форматтерах GostConstants.CALG_GR3411, rgbHash, rgbSignature); return(ret); }
/// <summary> /// Verifies the signature of a hash value. /// </summary> private bool VerifyHash(byte[] rgbHash, int calgHash, byte[] rgbSignature) { return(CapiHelper.VerifySign( SafeProvHandle, SafeKeyHandle, CapiHelper.CALG_RSA_SIGN, calgHash, rgbHash, rgbSignature)); }
/// <summary> /// Verifies the specified signature data by comparing it to the signature computed for the specified hash value. /// </summary> /// <param name="rgbHash">The hash value of the data to be signed.</param> /// <param name="str">The name of the hash algorithm used to create the hash value of the data.</param> /// <param name="rgbSignature">The signature data to be verified.</param> /// <returns>true if the signature verifies as valid; otherwise, false.</returns> public bool VerifyHash(byte[] rgbHash, string?str, byte[] rgbSignature) { ArgumentNullException.ThrowIfNull(rgbHash); ArgumentNullException.ThrowIfNull(rgbSignature); int calgHash = CapiHelper.NameOrOidToHashAlgId(str, OidGroup.HashAlgorithm); return(CapiHelper.VerifySign( SafeProvHandle, SafeKeyHandle, CapiHelper.CALG_DSS_SIGN, calgHash, rgbHash, rgbSignature)); }
/// <summary> /// Verifies the specified signature data by comparing it to the signature computed for the specified hash value. /// </summary> /// <param name="rgbHash">The hash value of the data to be signed.</param> /// <param name="str">The name of the hash algorithm used to create the hash value of the data.</param> /// <param name="rgbSignature">The signature data to be verified.</param> /// <returns>true if the signature verifies as valid; otherwise, false.</returns> public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature) { if (rgbHash == null) { throw new ArgumentNullException(nameof(rgbHash)); } if (rgbSignature == null) { throw new ArgumentNullException(nameof(rgbSignature)); } int calgHash = CapiHelper.NameOrOidToHashAlgId(str, OidGroup.HashAlgorithm); return(CapiHelper.VerifySign( SafeProvHandle, SafeKeyHandle, CapiHelper.CALG_DSS_SIGN, calgHash, rgbHash, rgbSignature)); }