Exemplo n.º 1
0
            public static unsafe int HashData(string hashAlgorithmId, ReadOnlySpan <byte> source, Span <byte> destination)
            {
                Interop.AppleCrypto.PAL_HashAlgorithm algorithm = HashAlgorithmNames.HashAlgorithmToPal(hashAlgorithmId);

                fixed(byte *pSource = source)
                fixed(byte *pDestination = destination)
                {
                    int digestSize;
                    int ret = Interop.AppleCrypto.DigestOneShot(
                        algorithm,
                        pSource,
                        source.Length,
                        pDestination,
                        destination.Length,
                        &digestSize);

                    if (ret != 1)
                    {
                        Debug.Fail($"HashData return value {ret} was not 1");
                        throw new CryptographicException();
                    }

                    Debug.Assert(digestSize <= destination.Length);

                    return(digestSize);
                }
            }
Exemplo n.º 2
0
            public AppleHmacProvider(string hashAlgorithmId, ReadOnlySpan <byte> key)
            {
                PAL_HashAlgorithm algorithm = HashAlgorithmNames.HashAlgorithmToPal(hashAlgorithmId);

                _liteHmac = new LiteHmac(algorithm, key, preinitialize: false);
                _key      = key.ToArray();
            }
Exemplo n.º 3
0
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
                throw new ArgumentNullException(nameof(rgbHash));
            if (PublicOnly)
                throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);

            HashAlgorithmName algName = HashAlgorithmNames.NameOrOidToHashAlgorithmName(str);
            return _impl.SignHash(rgbHash, algName, RSASignaturePadding.Pkcs1);
        }
Exemplo n.º 4
0
        public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
        {
            if (rgbHash == null)
                throw new ArgumentNullException(nameof(rgbHash));
            if (rgbSignature == null)
                throw new ArgumentNullException(nameof(rgbSignature));

            // _impl does remaining parameter validation

            HashAlgorithmName algName = HashAlgorithmNames.NameOrOidToHashAlgorithmName(str);
            return _impl.VerifyHash(rgbHash, rgbSignature, algName, RSASignaturePadding.Pkcs1);
        }
Exemplo n.º 5
0
 public override void SetHashAlgorithm(string strName)
 {
     // Verify the name
     if (CryptoConfig.MapNameToOID(strName) != null)
     {
         // Uppercase known names as required for BCrypt
         _algName = HashAlgorithmNames.ToUpper(strName);
     }
     else
     {
         // For .NET Framework compat, exception is deferred until VerifySignature
         _algName = null;
     }
 }
Exemplo n.º 6
0
        public override void SetHashAlgorithm(string strName)
        {
            try
            {
                // Verify the name
                Oid.FromFriendlyName(strName, OidGroup.HashAlgorithm);

                // Uppercase known names as required for BCrypt
                _algName = HashAlgorithmNames.ToUpper(strName);
            }
            catch (CryptographicException)
            {
                // For desktop compat, exception is deferred until VerifySignature
                _algName = null;
            }
        }
Exemplo n.º 7
0
        internal static LiteHmac CreateHmac(string hashAlgorithmId, ReadOnlySpan <byte> key)
        {
            PAL_HashAlgorithm algorithm = HashAlgorithmNames.HashAlgorithmToPal(hashAlgorithmId);

            return(new LiteHmac(algorithm, key, preinitialize: true));
        }
Exemplo n.º 8
0
        internal static LiteHash CreateHash(string hashAlgorithmId)
        {
            PAL_HashAlgorithm algorithm = HashAlgorithmNames.HashAlgorithmToPal(hashAlgorithmId);

            return(new LiteHash(algorithm));
        }
Exemplo n.º 9
0
 public bool VerifyData(byte[] buffer, object halg, byte[] signature) =>
     _impl.VerifyData(buffer, signature, HashAlgorithmNames.ObjToHashAlgorithmName(halg), RSASignaturePadding.Pkcs1);
Exemplo n.º 10
0
 public byte[] SignData(Stream inputStream, object halg) =>
     _impl.SignData(inputStream, HashAlgorithmNames.ObjToHashAlgorithmName(halg), RSASignaturePadding.Pkcs1);
Exemplo n.º 11
0
 public byte[] SignData(byte[] buffer, object halg) =>
     _impl.SignData(buffer, HashAlgorithmNames.ObjToHashAlgorithmName(halg), RSASignaturePadding.Pkcs1);