internal LiteHmac(PAL_HashAlgorithm algorithm, ReadOnlySpan <byte> key, bool preinitialize) { int hashSizeInBytes = 0; _ctx = Interop.AppleCrypto.HmacCreate(algorithm, ref hashSizeInBytes); if (hashSizeInBytes < 0) { _ctx.Dispose(); throw new PlatformNotSupportedException( SR.Format( SR.Cryptography_UnknownHashAlgorithm, Enum.GetName(typeof(Interop.AppleCrypto.PAL_HashAlgorithm), algorithm))); } if (_ctx.IsInvalid) { _ctx.Dispose(); throw new CryptographicException(); } if (preinitialize) { if (Interop.AppleCrypto.HmacInit(_ctx, key) != Success) { _ctx.Dispose(); throw new CryptographicException(); } } _hashSizeInBytes = hashSizeInBytes; }
public override void Dispose(bool disposing) { if (disposing) { _ctx?.Dispose(); Array.Clear(_key, 0, _key.Length); } }
internal AppleHmacProvider(Interop.AppleCrypto.PAL_HashAlgorithm algorithm, byte[] key) { _key = key.CloneByteArray(); int hashSizeInBytes = 0; _ctx = Interop.AppleCrypto.HmacCreate(algorithm, ref hashSizeInBytes); if (hashSizeInBytes < 0) { _ctx.Dispose(); throw new PlatformNotSupportedException( SR.Format( SR.Cryptography_UnknownHashAlgorithm, Enum.GetName(typeof(Interop.AppleCrypto.PAL_HashAlgorithm), algorithm))); } if (_ctx.IsInvalid) { _ctx.Dispose(); throw new CryptographicException(); } HashSizeInBytes = hashSizeInBytes; }
public void Dispose() { _ctx.Dispose(); }