using GostCryptography.Properties; using System; using System.Security.Cryptography; namespace GostCryptography.Base { /// /// Класс проверки цифровой подписи ГОСТ /// public class GostSignatureDeformatter : AsymmetricSignatureDeformatter { /// /// Конструктор /// public GostSignatureDeformatter() { } /// /// Конструктор /// /// Открытый ключ для проверки цифровой подписи /// /// public GostSignatureDeformatter(AsymmetricAlgorithm publicKey) : this() { SetKey(publicKey); } private GostAsymmetricAlgorithm _publicKey; /// public override void SetKey(AsymmetricAlgorithm publicKey) { if (publicKey == null) { throw ExceptionUtility.ArgumentNull(nameof(publicKey)); } if (!(publicKey is GostAsymmetricAlgorithm gostPublicKey)) { if (publicKey.SignatureAlgorithm.IndexOf("gost", StringComparison.OrdinalIgnoreCase) < 0) { throw ExceptionUtility.ArgumentOutOfRange(nameof(publicKey), Resources.ShouldSupportGost3410); } gostPublicKey = new GostExternalAsymmetricAlgorithm(publicKey); } _publicKey = gostPublicKey; } /// public override void SetHashAlgorithm(string hashAlgorithmName) { } /// public override bool VerifySignature(byte[] hash, byte[] signature) { if (hash == null) { throw ExceptionUtility.ArgumentNull(nameof(hash)); } if (signature == null) { throw ExceptionUtility.ArgumentNull(nameof(signature)); } var reverseSignature = (byte[])signature.Clone(); Array.Reverse(reverseSignature); return _publicKey.VerifySignature(hash, reverseSignature); } } }