Chủ Nhật, 8 tháng 1, 2017

Keyed Hash Algorithm examples in .Net

public static byte[] ComputeHmacsha1(byte[] toBeHashed, byte[] key)
{
    using (var hmac = new HMACSHA1(key))
    {
        return hmac.ComputeHash(toBeHashed);
    }
}
 
public static byte[] ComputeHmacsha256(byte[] toBeHashed, byte[] key)
{
    using (var hmac = new HMACSHA256(key))
    {
        return hmac.ComputeHash(toBeHashed);
    }
}
 
public static byte[] ComputeHmacsha512(byte[] toBeHashed, byte[] key)
{
    using (var hmac = new HMACSHA512(key))
    {
        return hmac.ComputeHash(toBeHashed);
    }
}
 
public static byte[] ComputeHmacmd5(byte[] toBeHashed, byte[] key)
{
    using (var hmac = new HMACMD5(key))
    {
        return hmac.ComputeHash(toBeHashed);
    }
}

Không có nhận xét nào :

Đăng nhận xét