public static string hash_value(string originalText, CryptoHashProviderType providerType) { HashAlgorithm hashAlgorithm = null; switch (providerType) { case CryptoHashProviderType.Md5: hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(SHA512.Create()); break; } if (hashAlgorithm == null) { return(string.Empty); } var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(originalText)); return(BitConverter.ToString(hash).Replace("-", string.Empty)); }
public static string hash_value(string originalText, CryptoHashProviderType providerType) { IHashAlgorithm hashAlgorithm = get_hash_algorithm_static(providerType); if (hashAlgorithm == null) return string.Empty; var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(originalText)); return BitConverter.ToString(hash).Replace("-", string.Empty); }
private static IHashAlgorithm get_hash_algorithm_static(CryptoHashProviderType algorithmType) { var fipsOnly = false; try { fipsOnly = CryptoConfig.AllowOnlyFipsAlgorithms; } catch (Exception ex) { "chocolatey".Log().Debug("Unable to get FipsPolicy from CryptoConfig:{0} {1}".format_with(Environment.NewLine, ex.Message)); } HashAlgorithm hashAlgorithm = null; switch (algorithmType) { case CryptoHashProviderType.Md5: hashAlgorithm = new HashAlgorithm(MD5.Create()); break; #if NETFRAMEWORK case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA1Cng() : SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA256Cng() : SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA512Cng() : SHA512.Create()); break; #else // On .net core there does not exists SHA1Cng/SHA256Cng/SHA512Cng - there exists SHA1Managed alternative // but it's not clear whether they map one to one. Maybe some obsolete .NET Framework feature ? case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(SHA512.Create()); break; #endif } return(hashAlgorithm); }
public static string hash_value(string originalText, CryptoHashProviderType providerType) { IHashAlgorithm hashAlgorithm = get_hash_algorithm_static(providerType); if (hashAlgorithm == null) { return(string.Empty); } var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(originalText)); return(BitConverter.ToString(hash).Replace("-", string.Empty)); }
public CrytpoHashProvider(IFileSystem fileSystem, CryptoHashProviderType providerType) { _fileSystem = fileSystem; switch (providerType) { case CryptoHashProviderType.Md5: _hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: _hashAlgorithm = new HashAlgorithm(SHA1.Create()); break; case CryptoHashProviderType.Sha256: _hashAlgorithm = new HashAlgorithm(SHA256.Create()); break; case CryptoHashProviderType.Sha512: _hashAlgorithm = new HashAlgorithm(SHA512.Create()); break; } }
public CrytpoHashProvider(IFileSystem fileSystem, CryptoHashProviderType providerType) { _fileSystem = fileSystem; switch (providerType) { case CryptoHashProviderType.Md5: _hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: _hashAlgorithm = new HashAlgorithm(SHA1.Create()); break; case CryptoHashProviderType.Sha256: _hashAlgorithm = new HashAlgorithm(SHA256.Create()); break; case CryptoHashProviderType.Sha512: _hashAlgorithm = new HashAlgorithm(SHA512.Create()); break; } }
private static IHashAlgorithm get_hash_algorithm_static(CryptoHashProviderType algorithmType) { var fipsOnly = false; try { fipsOnly = CryptoConfig.AllowOnlyFipsAlgorithms; } catch (Exception ex) { "chocolatey".Log().Debug("Unable to get FipsPolicy from CryptoConfig:{0} {1}".format_with(Environment.NewLine, ex.Message)); } HashAlgorithm hashAlgorithm = null; switch (algorithmType) { case CryptoHashProviderType.Md5: hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA1Cng() : SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA256Cng() : SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA512Cng() : SHA512.Create()); break; } return(hashAlgorithm); }
public static string hash_value(string originalText, CryptoHashProviderType providerType) { HashAlgorithm hashAlgorithm = null; switch (providerType) { case CryptoHashProviderType.Md5: hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(SHA512.Create()); break; } if (hashAlgorithm == null) return string.Empty; var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(originalText)); return BitConverter.ToString(hash).Replace("-", string.Empty); }
public void set_hash_algorithm(CryptoHashProviderType algorithmType) { _hashAlgorithm = get_hash_algorithm_static(algorithmType); }
public void set_hash_algorithm(CryptoHashProviderType algorithmType) { _hashAlgorithm = get_hash_algorithm_static(algorithmType); }
private static IHashAlgorithm get_hash_algorithm_static(CryptoHashProviderType algorithmType) { var fipsOnly = false; try { fipsOnly = CryptoConfig.AllowOnlyFipsAlgorithms; } catch (Exception ex) { "chocolatey".Log().Debug("Unable to get FipsPolicy from CryptoConfig:{0} {1}".format_with(Environment.NewLine, ex.Message)); } HashAlgorithm hashAlgorithm = null; switch (algorithmType) { case CryptoHashProviderType.Md5: hashAlgorithm = new HashAlgorithm(MD5.Create()); break; case CryptoHashProviderType.Sha1: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA1Cng() : SHA1.Create()); break; case CryptoHashProviderType.Sha256: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA256Cng() : SHA256.Create()); break; case CryptoHashProviderType.Sha512: hashAlgorithm = new HashAlgorithm(fipsOnly ? new SHA512Cng() : SHA512.Create()); break; } return hashAlgorithm; }