public IReadOnlyCollection <byte> ToBase64Bytes(string input) { if (input == null) { return(null); } var inputBytes = ByteConverter.ConvertToBytes(input).ToArray(); var resultString = ToBase64String(inputBytes); var result = ByteConverter.ConvertToBytes(resultString).ToArray(); return(result); }
/// <summary> /// Hashes the <paramref name="item"/> provided and passes the hashed result to an action for processing (typically setting bits in the bit array or checking if those bits are set) /// </summary> /// <param name="item"></param> /// <param name="hashAction"></param> protected virtual void DoHashAction(T item, Action <int> hashAction) { var bytes = item as byte[] ?? _byteConverter.ConvertToBytes(item); var hashes = _hasher.GetHashesOptimized(bytes, NumberHashes, CollectionLength); for (var i = 0; i < hashes.Length; i++) { hashAction(hashes[i]); } }
/// <summary> /// Hashes the <paramref name="item"/> provided and passes the hashed result to an action for processing (typically setting bits in the bit array or checking if those bits are set) /// </summary> /// <param name="item"></param> /// <param name="hashAction"></param> protected void DoHashAction(T item, Action <int> hashAction) { var bytes = item as byte[] ?? _byteConverter.ConvertToBytes(item); var hashes = _hasher.GetHashes(bytes, NumberHashes, CollectionLength); foreach (var hash in hashes) { hashAction(hash); } }
private static string HashCore(IByteConverter byteConverter, SHA512 hasher, string value) { // setup encoding, hash, and read byte array var clearBytes = byteConverter.ConvertToBytes(value).EnsureArray(); // perform hashing operation var hashBytes = hasher.ComputeHash(clearBytes); // convert back to string var result = hashBytes.ToHex(); return(result); }
public void When_FromBase64Bytes_GivenEmptyString_ExpectEmptyString() { // arrange const string input = ""; const string expected = ""; // act var inputBytes = _UTF8Converter.ConvertToBytes(input); var actual = _Base64Converter.FromBase64Bytes(inputBytes); // assert Assert.IsNotNull(actual); Assert.AreEqual(expected: expected, actual: actual); }
private static byte[] ConvertToUTF8Bytes(IByteConverter byteConverter, string input) { var result = byteConverter.ConvertToBytes(input).EnsureArray(); return(result); }