public static byte[] SymmetricSign(byte[] key, ArraySegment <byte> data, SecurityPolicy policy) { using (MemoryStream memoryStream = new MemoryStream(data.Array, data.Offset, data.Count)) { return(UASecurity.HMACForSecurityPolicy(key, policy).ComputeHash(memoryStream)); } }
public static byte[] PSHA(byte[] secret, byte[] seed, int length, SecurityPolicy policy) { HMAC hmac = UASecurity.HMACForSecurityPolicy(secret, policy); int val1 = UASecurity.SignatureSizeForSecurityPolicy(policy); byte[] hash1 = hmac.ComputeHash(seed); byte[] buffer = new byte[val1 + seed.Length]; Array.Copy(hash1, buffer, hash1.Length); Array.Copy(seed, 0, buffer, hash1.Length, seed.Length); byte[] numArray = new byte[length]; int destinationIndex = 0; while (destinationIndex < length) { byte[] hash2 = hmac.ComputeHash(buffer); int length1 = Math.Min(val1, length - destinationIndex); Array.Copy(hash2, 0, numArray, destinationIndex, length1); destinationIndex += length1; hash1 = hmac.ComputeHash(hash1); Array.Copy(hash1, buffer, hash1.Length); } return(numArray); }