using System;
using System.Security.Cryptography;
namespace Jd.ACES.Common
{
public class KeyDerivation
{
///
/// Computes key ID based on service identifier and key version of specified master key.
///
/// The service identifier of specified master key.
/// The key version of specified master key.
/// The base64 encoding string of computed key ID.
public static string KeyIDString(string identifier, uint version)
{
return Convert.ToBase64String(KeyIDBytes(identifier, version),
Base64FormattingOptions.None);
}
///
/// Computes key ID based on service identifier and key version of specified master key.
///
/// The service identifier of specified master key.
/// The key version of specified master key.
/// The byte array of computed key ID.
public static byte[] KeyIDBytes(string identifier, uint version)
{
string id = identifier + ":" + version;
byte[] keyidArr = null;
using (MD5 hash = MD5.Create())
{
keyidArr = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(id));
}
return keyidArr;
}
}
}