コード例 #1
0
        /// <inheritdoc />
        protected internal override byte[] Sign(byte[] data)
        {
            using (var algorithm = MacAlgorithmProvider.GetAlgorithm(this.algorithm))
            {
#if __ANDROID__
                using Javax.Crypto.Spec.SecretKeySpec key = MacAlgorithmProvider.GetSecretKey(this.algorithm, this.key);
                algorithm.Init(key);
                return(algorithm.DoFinal(data) !);
#else
                algorithm.Key = this.key;
                return(algorithm.ComputeHash(data));
#endif
            }
        }
コード例 #2
0
        /// <inheritdoc />
        protected internal override bool VerifySignature(byte[] data, byte[] signature)
        {
            using (var algorithm = MacAlgorithmProvider.GetAlgorithm(this.algorithm))
            {
                byte[] computedMac;
#if __ANDROID__
                using Javax.Crypto.Spec.SecretKeySpec key = MacAlgorithmProvider.GetSecretKey(this.algorithm, this.key);
                algorithm.Init(key);
                computedMac = algorithm.DoFinal(data) !;
#else
                algorithm.Key = this.key;
                computedMac   = algorithm.ComputeHash(data);
#endif
                return(CryptoUtilities.BufferEquals(computedMac, signature));
            }
        }