/// <summary> /// String to MD5 /// </summary> /// <returns>The hash.</returns> /// <param name="s">String</param> public static string ToMD5(this string s) { IHashAlgorithmProvider algoProv = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); byte[] dataTB = Encoding.UTF8.GetBytes(s); return(ByteArrayToHex(algoProv.HashData(dataTB))); }
public KetamaPool(string name, IHashAlgorithmProvider hashAlgorithmProvider) { Name = name; m_hashAlgorithmProvider = hashAlgorithmProvider; m_hashes = new List <uint>(); m_items = new Dictionary <uint, T>(); }
public static string GenerateFor(DeviceConsistencyCommitment commitment, List <DeviceConsistencySignature> signatures) { try { List <DeviceConsistencySignature> sortedSignatures = new List <DeviceConsistencySignature>(signatures); sortedSignatures.Sort(new SignatureComparator()); IHashAlgorithmProvider messageDigest = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512); byte[] hash = messageDigest.HashData(ByteUtil.Combine(new byte[][] { ByteUtil.ShortToByteArray(CodeVersion), commitment.ToByteArray() })); foreach (DeviceConsistencySignature signature in sortedSignatures) { hash = messageDigest.HashData(ByteUtil.Combine(new byte[][] { hash, signature.GetVrfOutput() })); } string digits = GetEncodedChunk(hash, 0) + GetEncodedChunk(hash, 5); return(digits.Substring(0, 6)); } catch (Exception e) { Debug.Assert(false, e.Message); throw e; } }
private void Init(string algorithmName) { var algorithm = (HashAlgorithm)Enum.Parse(typeof(HashAlgorithm), algorithmName); _hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(algorithm); Clear(); }
private string getDisplayStringFor(string stableIdentifier, IdentityKey identityKey) { try { IHashAlgorithmProvider digest = HashAlgorithmProvider.OpenAlgorithm(PCLCrypto.HashAlgorithm.Sha512); byte[] publicKey = identityKey.getPublicKey().serialize(); byte[] hash = ByteUtil.combine(ByteUtil.shortToByteArray(VERSION), publicKey, Encoding.UTF8.GetBytes(stableIdentifier)); for (int i = 0; i < iterations; i++) { hash = digest.HashData(ByteUtil.combine(new byte[][] { hash, publicKey })); } return(getEncodedChunk(hash, 0) + getEncodedChunk(hash, 5) + getEncodedChunk(hash, 10) + getEncodedChunk(hash, 15) + getEncodedChunk(hash, 20) + getEncodedChunk(hash, 25)); } catch (Exception e) { Debug.Assert(false, e.Message); throw e; } }
public DeviceConsistencyCommitment(int generation, List <IdentityKey> identityKeys) { try { List <IdentityKey> sortedIdentityKeys = new List <IdentityKey>(identityKeys); sortedIdentityKeys.Sort(new IdentityKeyComparator()); IHashAlgorithmProvider messageDigest = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512); _serialized = messageDigest.HashData(ByteUtil.Combine(new byte[][] { Encoding.UTF8.GetBytes(Version), ByteUtil.IntToByteArray(generation) })); foreach (IdentityKey commitment in sortedIdentityKeys) { _serialized = messageDigest.HashData(ByteUtil.Combine(new byte[][] { _serialized, commitment.GetPublicKey().Serialize() })); } _generation = generation; } catch (Exception e) { Debug.Assert(false, e.Message); throw e; } }
private byte[] GetFingerprint(int iterations, string stableIdentifier, List <IdentityKey> unsortedIdentityKeys) { try { IHashAlgorithmProvider digest = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512); byte[] publicKey = GetLogicalKeyBytes(unsortedIdentityKeys); byte[] hash = ByteUtil.Combine(ByteUtil.ShortToByteArray(FingerprintVersion), publicKey, Encoding.UTF8.GetBytes(stableIdentifier)); for (int i = 0; i < iterations; i++) { hash = digest.HashData(ByteUtil.Combine(new byte[][] { hash, publicKey })); } return(hash); } catch (Exception e) { Debug.Assert(false, e.Message); throw e; } }
public Distributed(DistributedOptions options, IHashAlgorithmProvider hashAlgorithmProvider) { Options = options; Pool = new SynchronizedKetamaPool <IClient>("Distributed", hashAlgorithmProvider, options.ClientAccessTimeout); Idle = new SynchronizedPool <IClient>(m_sync, new IdleTimeoutPool <IClient>(m_sync, new StackPool <IClient>("Distributed Idle", options.IdlePoolSize), RetryIdled, options.IdleLeaseTime, options.IdleLeaseTime), options.IdleAccessTimeout); }
private static string Encode(string input, HashAlgorithm algorithm) { IHashAlgorithmProvider provider = HashAlgorithmProvider.OpenAlgorithm(algorithm); byte[] data = provider.HashData(CryptographicBuffer.ConvertStringToBinary(input, Encoding.UTF8)); return(CryptographicBuffer.EncodeToHexString(data)); }
public HashRandomOracle(IHashAlgorithmProvider hashAlgorithmProvider) { if (hashAlgorithmProvider == null) { throw new ArgumentNullException(nameof(hashAlgorithmProvider)); } _hashAlgorithm = hashAlgorithmProvider.Create(); }
/// <inheritdoc /> public string Md5(string value) { IHashAlgorithmProvider algoProv = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); byte[] dataB = Encoding.UTF8.GetBytes(value); byte[] dataHash = algoProv.HashData(dataB); var hex = new StringBuilder(dataHash.Length * 2); foreach (byte b in dataHash) { hex.AppendFormat("{0:x2}", b); } return(hex.ToString()); }
public HashEncoder(IHashAlgorithmProvider algorithmProvider, IEncoder inner) { if (inner == null) { throw new ArgumentNullException("inner"); } if (algorithmProvider == null) { throw new ArgumentNullException("algorithmProvider"); } m_inner = inner; m_algorithmProvider = algorithmProvider; }
/// <summary> /// Calculates and returns password hash as required by SugarCrm REST API calls /// </summary> /// <param name="password">The user supplied plain password</param> /// <returns>Hased password</returns> public static string CalculateMd5Hash(string password) { IHashAlgorithmProvider algoProv = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); byte[] inputBytes = Encoding.UTF8.GetBytes(password); byte[] hash = algoProv.HashData(inputBytes); var stringBuilder = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { stringBuilder.Append(hash[i].ToString("x2")); } return(stringBuilder.ToString()); }
/// <summary> /// Encodes a string into it's MD5 string. /// </summary> /// <param name="input">The text to encode.</param> /// <returns>The encoded string.</returns> public static string Md5Encode(this string input) { // step 1, calculate MD5 hash from input IHashAlgorithmProvider hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); byte[] inputBytes = Encoding.UTF8.GetBytes(input); byte[] hash = hasher.HashData(inputBytes); var sb = new StringBuilder(); foreach (byte character in hash) { sb.Append(character.ToString("X2", CultureInfo.InvariantCulture)); } return(sb.ToString().ToUpperInvariant()); }
private static string hash(byte[] bytes, HashAlgorithm algorithmName) { //grab the algoritm IHashAlgorithmProvider algorithm = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(algorithmName); //hash the data byte[] hash = algorithm.HashData(bytes); //verify that hash succeeded if (hash.Length != algorithm.HashLength) { throw new Exception("There was an error creating the hash."); } //convert to string return(WinRTCrypto.CryptographicBuffer.EncodeToHexString(hash)); }
/* This method creates a hash of a plain string password */ /* concatenated with a salt value */ public static string HashPassword(string password, string salt) { /* Change the string encoding of the password and salt and */ /* append the salt to the password */ byte[] _plainPassword = Encoding.UTF8.GetBytes(password); byte[] _plainSalt = Encoding.UTF8.GetBytes(salt); byte[] _saltedPassword = AppendArray(_plainPassword, _plainSalt); /* Use the appropriate hashing algorithm and return the hashed */ /* password */ IHashAlgorithmProvider hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm( HashAlgorithm.Sha512); byte[] _hashPassword = hasher.HashData(_saltedPassword); return(Convert.ToBase64String(_hashPassword)); }
public byte[] GenerateHash() { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(_displayName == null ? "" : _displayName); bw.Write(_hardCurrency); SaveGameData(bw); SaveTowerData(bw); SaveVipData(bw); IHashAlgorithmProvider algoProv = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); _hash = algoProv.HashData(ms.ToArray()); bw.Dispose(); return(_hash); }
public static string Hash(string password) { IHashAlgorithmProvider hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1); byte[] data = Encoding.UTF8.GetBytes(password); byte[] hashed = hasher.HashData(data); StringBuilder builder = new StringBuilder(); foreach (byte b in hashed) { string part = string.Format("{0:X}", b); for (int i = part.Length; i < 2; ++i) { builder.Append("0"); } builder.Append(part); } return(builder.ToString().ToLowerInvariant()); }
public DefaultClientFactory(ConnectionOptions[] connectionOptions, DistributedOptions distributedOptions, IHashAlgorithmProvider hashAlgorithmProvider) { if (connectionOptions.Length > 1) { var distributed = new Distributed(distributedOptions, hashAlgorithmProvider); var clients = new IClient[connectionOptions.Length]; for (int i = 0; i < connectionOptions.Length; i++) { clients[i] = CreateClient(connectionOptions[i]); } distributed.AddRange(clients); m_slaves = clients; m_master = distributed; } else { m_master = CreateClient(connectionOptions[0]); } }
public HasherBase(IHashAlgorithmProvider algorithmProvider) { this._algorithmProvider = algorithmProvider ?? throw new ArgumentNullException(nameof(algorithmProvider)); }
public PasswordEncryptionManager(IHashAlgorithmProvider hashAlgorithmProvider, IUserService userService) { _hashAlgorithmProvider = hashAlgorithmProvider; _userService = userService; }
public SynchronizedKetamaPool(string name, IHashAlgorithmProvider hashAlgorithmProvider, int timeout) : base(name, hashAlgorithmProvider) { m_timeout = timeout; m_lockScope = new ReaderWriterLockScope(new ReaderWriterLock()); }
public CryptoContext(RandomNumberGenerator randomNumberGenerator, IHashAlgorithmProvider hashAlgorithmProvider) { RandomNumberGenerator = randomNumberGenerator; HashAlgorithmProvider = hashAlgorithmProvider; }
private MD5(IHashAlgorithmProvider provider) => this.Provider = provider;
public PasswordEncryptionManagerTests() { _hashAlgorithmProvider = A.Fake <IHashAlgorithmProvider>(); _userService = A.Fake <IUserManagementService>(); _passwordEncryptionManager = new PasswordEncryptionManager(_hashAlgorithmProvider, _userService); }
public PasswordEncryptionManagerTests() { _hashAlgorithmProvider = A.Fake<IHashAlgorithmProvider>(); _userService = A.Fake<IUserService>(); _passwordEncryptionManager = new PasswordEncryptionManager(_hashAlgorithmProvider, _userService); }
public HashRandomOracleProvider(IHashAlgorithmProvider hashAlgorithmProvider) { _hashAlgorithmProvider = hashAlgorithmProvider; }
public TestablePasswordEncryptionManager(IHashAlgorithmProvider hashAlgorithmProvider, IUserManagementService userService) : base(hashAlgorithmProvider, userService) { }
public PCLCryptographer(HashAlgorithm algorithm = HashAlgorithm.Md5) { _hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(algorithm); }
public void OpenAlgorithm() { IHashAlgorithmProvider provider = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1); Assert.NotNull(provider); }
public TestablePasswordEncryptionManager(IHashAlgorithmProvider hashAlgorithmProvider, IUserService userService) : base(hashAlgorithmProvider, userService) { }