C# PCL HMACSHAX with BouncyCastle-PCL

十年热恋 提交于 2019-12-06 07:06:42

Try like this for HmacSha256

public class HmacSha256
    {
        private readonly HMac _hmac;

        public HmacSha256(byte[] key)
        {
            _hmac = new HMac(new Sha256Digest());
            _hmac.Init(new KeyParameter(key));
        }

        public byte[] ComputeHash(byte[] value)
        {
            if (value == null) throw new ArgumentNullException("value");

            byte[] resBuf = new byte[_hmac.GetMacSize()];
            _hmac.BlockUpdate(value, 0, value.Length);
            _hmac.DoFinal(resBuf, 0);

            return resBuf;
        }
    }

The same should be for other two...

This is just a follow up because it shows up on Google. The PCLCrypto Library does implement all the hash methods, but not in the PCL dll. The PCL dll is only a stub, and the actual implementations are in the platform specific DLLs.

Just make sure you reference the PCLCrypto library from ALL your projects, and not just the PCL library.

The technique is called bait-and-switch and is used because it allows for the end application to utilize the system specific crypto apis (for faster performance)

See https://github.com/AArnott/PCLCrypto#installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!