Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HmacSha2"/> class.
        /// </summary>
        /// <param name="sha2"></param>
        /// <param name="key"></param>
        protected HmacSha2(Sha2 sha2, ReadOnlySpan <byte> key)
        {
            if (sha2 is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.sha);
            }

            Sha2         = sha2;
            _keys        = new byte[BlockSize * 2];
            _innerPadKey = new ReadOnlyMemory <byte>(_keys, 0, BlockSize);
            _outerPadKey = new ReadOnlyMemory <byte>(_keys, BlockSize, BlockSize);
            if (key.Length > BlockSize)
            {
                Span <byte> keyPrime = stackalloc byte[sha2.HashSize];
                Sha2.ComputeHash(key, keyPrime, default, default);
Esempio n. 2
0
 /// <summary>Initializes a new instance of <see cref="SignatureAlgorithm"/>. </summary>
 public SignatureAlgorithm(AlgorithmId id, string name, AlgorithmCategory category, ushort requiredKeySizeInBits, HashAlgorithmName hashAlgorithm)
 {
     _id       = id;
     _name     = JsonEncodedText.Encode(name);
     _category = category;
     _requiredKeySizeInBits = requiredKeySizeInBits;
     _hashAlgorithm         = hashAlgorithm;
     _sha = hashAlgorithm.Name switch
     {
         "SHA256" => Sha256.Shared,
         "SHA384" => Sha384.Shared,
         "SHA512" => Sha512.Shared,
         _ => ShaNull.Shared
     };
 }
 /// <summary>Initializes a new instance of <see cref="KeyManagementAlgorithm"/>. </summary>
 public KeyManagementAlgorithm(AlgorithmId id, string name, AlgorithmCategory keyType, KeyManagementAlgorithm wrappedAlgorithm, Sha2 sha2)
     : this(id, name, keyType, requiredKeySizeInBits : 0, wrappedAlgorithm, sha2 : sha2, produceEncryptedKey : true)
 {
 }
Esempio n. 4
0
 public static void ComputeHash(this Sha2 sha2, ReadOnlySpan <byte> source, Span <byte> destination)
 {
     sha2.ComputeHash(source, destination, default, default);