public static byte[] Sign(byte[] input, CngKey key, CngAlgorithm hash, int saltSize) { byte[] numArray; using (HashAlgorithm hashAlgorithm = RsaPss.HashAlgorithm(hash)) { numArray = RsaPss.SignHash(hashAlgorithm.ComputeHash(input), key, hash.Algorithm, saltSize); } return(numArray); }
public static bool Verify(byte[] securedInput, byte[] signature, CngKey key, CngAlgorithm hash, int saltSize) { bool flag; using (HashAlgorithm hashAlgorithm = RsaPss.HashAlgorithm(hash)) { flag = RsaPss.VerifyHash(hashAlgorithm.ComputeHash(securedInput), signature, key, hash.Algorithm, saltSize); } return(flag); }
public bool Verify(byte[] signature, byte[] securedInput, object key) { var publicKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type."); try { return(RsaPss.Verify(securedInput, signature, RsaKey.New(publicKey.ExportParameters(false)), Hash, saltSize)); } catch (CryptographicException e) { return(false); } }
public byte[] Sign(byte[] securedInput, object key) { var privateKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type."); try { return(RsaPss.Sign(securedInput, RsaKey.New(privateKey.ExportParameters(true)), Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } }
public bool Verify(byte[] signature, byte[] securedInput, object key) { bool flag; RSACryptoServiceProvider rSACryptoServiceProvider = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type.", new object[0]); try { flag = RsaPss.Verify(securedInput, signature, RsaKey.New(rSACryptoServiceProvider.ExportParameters(false)), this.Hash, this.saltSize); } catch (CryptographicException cryptographicException) { flag = false; } return(flag); }
public byte[] Sign(byte[] securedInput, object key) { byte[] numArray; RSACryptoServiceProvider rSACryptoServiceProvider = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type.", new object[0]); try { numArray = RsaPss.Sign(securedInput, RsaKey.New(rSACryptoServiceProvider.ExportParameters(true)), this.Hash, this.saltSize); } catch (CryptographicException cryptographicException) { throw new JoseException("Unable to sign content.", cryptographicException); } return(numArray); }
public byte[] Sign(byte[] securedInput, object key) { #if NET40 var privateKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type."); try { return(RsaPss.Sign(securedInput, RsaKey.New(privateKey.ExportParameters(true)), Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } #elif NETSTANDARD1_4 var privateKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(privateKey.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public byte[] Sign(byte[] securedInput, object key) { #if NET40 || NET461 var privateKey = Ensure.Type <CngKey>(key, "RsaUsingSha with PSS padding alg expects key to be of CngKey type."); try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } #elif NETSTANDARD1_4 var privateKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(privateKey.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public bool Verify(byte[] signature, byte[] securedInput, object key) { #if NET40 || NET461 var publicKey = Ensure.Type <CngKey>(key, "RsaUsingSha with PSS padding alg expects key to be of CngKey type."); try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } #elif NETSTANDARD1_4 var publicKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(publicKey.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public bool Verify(byte[] signature, byte[] securedInput, object key) { #if NET40 var publicKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaUsingSha with PSS padding alg expects key to be of RSACryptoServiceProvider type."); try { return(RsaPss.Verify(securedInput, signature, RsaKey.New(publicKey.ExportParameters(false)), Hash, saltSize)); } catch (CryptographicException e) { return(false); } #elif NETSTANDARD1_4 var publicKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(publicKey.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public bool Verify(byte[] signature, byte[] securedInput, object key) { #if NET40 if (key is CngKey) { var publicKey = (CngKey)key; try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var publicKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(false)); try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of CngKey type."); #elif NET461 if (key is CngKey) { var publicKey = (CngKey)key; try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var publicKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(false)); try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } if (key is RSA) { var publicKey = (RSA)key; return(publicKey.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either CngKey or RSA types."); #elif NETSTANDARD var publicKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(publicKey.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public byte[] Sign(byte[] securedInput, object key) { #if NET40 if (key is CngKey) { var privateKey = (CngKey)key; try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } else if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(true)); try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of CngKey type."); #elif NET461 || NETSTANDARD2_0 if (key is CngKey) { var privateKey = (CngKey)key; try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(true)); try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } if (key is RSA) { var privateKey = (RSA)key; return(privateKey.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either CngKey or RSA types."); #elif NETSTANDARD1_4 var privateKey = Ensure.Type <RSA>(key, "RsaUsingSha with PSS padding alg expects key to be of RSA type."); return(privateKey.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); #endif }
public byte[] Sign(byte[] securedInput, object key) { #if NET40 if (key is CngKey cngKey) { try { return(RsaPss.Sign(securedInput, cngKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(rsaKey.ExportParameters(true)); try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of CngKey type."); #elif NET461 || NET472 if (key is CngKey cngKey) { try { return(RsaPss.Sign(securedInput, cngKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(rsaKey.ExportParameters(true)); try { return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize)); } catch (CryptographicException e) { throw new JoseException("Unable to sign content.", e); } } else if (key is RSA rsa) { return(rsa.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); } } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either CngKey or RSA types or Jwk type with kty='RSA'"); #elif NETSTANDARD if (key is RSA rsa) { return(rsa.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss)); } } throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either RSA type or Jwk type with kty='RSA'"); #endif }