I want to implement this logic in portable C# class:
static JsonWebToken()
{
HashAlgorithms = new Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>>
{
{ JwtHashAlgorithm.HS256, (key, value) => { using (var sha = new HMACSHA256(key)) { return sha.ComputeHash(value); } } },
{ JwtHashAlgorithm.HS384, (key, value) => { using (var sha = new HMACSHA384(key)) { return sha.ComputeHash(value); } } },
{ JwtHashAlgorithm.HS512, (key, value) => { using (var sha = new HMACSHA512(key)) { return sha.ComputeHash(value); } } }
};
}
but HMACSHA256
, HMACSHA384
and HMACSHA512
does not exist in portable
library.
First I try with https://github.com/AArnott/PCLCrypto
but I always get: An exception of type 'System.NotImplementedException' occurred in PCLCrypto.dll but was not handled in user code
I checked then code and I saw Crpyto for PCL is not implemented and always throw an exception
Then i found this library: https://github.com/onovotny/BouncyCastle-PCL
But there is no documentation how to use it. Can someone give me an exmaple how to implement
var sha = new HMACSHA256(key)
var sha = new HMACSHA384(key)
var sha = new HMACSHA512(key)
with BouncyCastle-PCL.