protected override void HashCore(byte[] rgb, int ibStart, int cbSize) { if (rgb != null && rgb.Length > 0 && cbSize > 0) { Win32ExtUtil.HashData(this.safeHashHandle, rgb, ibStart, cbSize); } }
public HashAlgGost2001Win() { this.HashSizeValue = Gost3411Consts.HashSizeValue; SafeHashHandleCP invalidHandle = SafeHashHandleCP.InvalidHandle; Win32ExtUtil.CreateHash(Win32ExtUtil.StaticGost2001ProvHandle, Gost3411Consts.HashAlgId, ref invalidHandle); this.safeHashHandle = invalidHandle; }
public override void Initialize() { if (this.safeHashHandle != null && !this.safeHashHandle.IsClosed) { this.safeHashHandle.Dispose(); } SafeHashHandleCP invalidHandle = SafeHashHandleCP.InvalidHandle; Win32ExtUtil.CreateHash(Win32ExtUtil.StaticGost2001ProvHandle, Gost3411Consts.HashAlgId, ref invalidHandle); this.safeHashHandle = invalidHandle; }
/// <summary> /// Метод вычисления подписи без использования закрытого ключа /// </summary> /// <param name="prefix"></param> /// <param name="certificate"></param> public void ComputeSignatureWithoutPrivateKey(string prefix, IntPtr certificate) { if (SignServiceUtils.IsUnix) { CryptoConfig.AddAlgorithm(typeof(HashAlgGost2001Unix), new string[1] { "http://www.w3.org/2001/04/xmldsig-more#gostr3411" }); CryptoConfig.AddAlgorithm(typeof(HashAlgGost2012_256Unix), new string[1] { "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256" }); CryptoConfig.AddAlgorithm(typeof(HashAlgGost2012_512Unix), new string[1] { "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-512" }); } else { CryptoConfig.AddAlgorithm(typeof(HashAlgGost2001Win), new string[1] { "http://www.w3.org/2001/04/xmldsig-more#gostr3411" }); CryptoConfig.AddAlgorithm(typeof(HashAlgGost2012_256Win), new string[1] { "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256" }); CryptoConfig.AddAlgorithm(typeof(HashAlgGost2012_512Win), new string[1] { "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-512" }); } CryptoConfig.AddAlgorithm(typeof(SmevTransformAlg), new string[1] { SmevTransformAlg.ALGORITHM_URI }); BuildDigestedReferences(); int algId = 0; HashAlgorithm hash = SignServiceUtils.GetHashAlgObject(certificate, ref algId); GetDigest(hash, prefix); uint keySpec = CApiExtConst.AT_SIGNATURE; IntPtr cpHandle = (SignServiceUtils.IsUnix) ? UnixExtUtil.GetHandler(certificate, out keySpec) : Win32ExtUtil.GetHandler(certificate, out keySpec); byte[] sign = (SignServiceUtils.IsUnix) ? UnixExtUtil.SignValue(cpHandle, (int)keySpec, hash.Hash, (int)0, algId) : Win32ExtUtil.SignValue(cpHandle, (int)keySpec, hash.Hash, (int)0, algId); Array.Reverse(sign); m_signature.SignatureValue = sign; SignServiceUtils.ReleaseProvHandle(cpHandle); }
protected override byte[] HashFinal() { return(Win32ExtUtil.EndHash(this.safeHashHandle)); }