CryptoSys PKI Pro Manual

Hmac.BytesFromBytes Method

Create a keyed-hash HMAC in byte format from byte input.

Syntax

[C#]
public static byte[] BytesFromBytes(
   byte[] message,
   byte[] key,
   HashAlgorithm hashAlg 
)
[VB]
Public Shared Function BytesFromBytes (
   message As Byte(),
   key As Byte(),
   hashAlg As HashAlgorithm 
) As Byte()

Parameters

message  Byte
Message to be signed in byte format
key  Byte
Key in byte format
hashAlg  HashAlgorithm
Hash algorithm to be used

Return Value

Byte
HMAC in byte format

Example

Console.WriteLine("HMAC Test case 4 from [RFC2202] and [RFC4231]...");
//  Test case 4 from [RFC2202] and [RFC4231]
//    key =           0x0102030405060708090a0b0c0d0e0f10111213141516171819
//    key_len         25
//    data =          0xcd repeated 50 times
//    data_len =      50
int i;
byte[] key = new byte[25];
for (i = 0; i < 25; i++)
key[i] = (byte)(i + 1);
byte[] msg = new byte[50];
for (i = 0; i < 50; i++)
msg[i] = 0xcd;
// Compute HMAC-SHA-256
byte[] b = Hmac.BytesFromBytes(msg, key, HashAlgorithm.Sha256);
Console.WriteLine("HMAC-SHA-256(50(0xcd), 0x0102..19)=\n{0}", Cnv.ToHex(b));
// 82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8077A2E3FF46729665B

See Also

VB6/C equivalent: HMAC_Bytes

[Contents] [Index]

[PREV: HexExtension.ToHex Method...]   [Contents]   [Index]   
   [NEXT: Hmac.HexFromBytes Method...]

Copyright © 2004-26 D.I. Management Services Pty Ltd t/a CryptoSys. All rights reserved. Generated 2026-09-21T05:59:39Z.