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 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 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 bool Verify(byte[] signature, byte[] securedInput, object key) { #if NET40 if (key is CngKey cngKey) { try { return(RsaPss.Verify(securedInput, signature, cngKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var publicKey = RsaKey.New(rsaKey.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 || NET472 if (key is CngKey cngKey) { try { return(RsaPss.Verify(securedInput, signature, cngKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var publicKey = RsaKey.New(rsaKey.ExportParameters(false)); try { return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize)); } catch (CryptographicException e) { return(false); } } else if (key is RSA rsa) { return(rsa.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().VerifyData(securedInput, signature, 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.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().VerifyData(securedInput, signature, 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 }