public string Encrypt(string message) { byte[] result = null; StringBuilder hash = new StringBuilder(); switch (HashSize) { case HashFunctionSize.Bits224: result = Sha3.Sha3224().ComputeHash(Encoding.UTF8.GetBytes(message)); break; case HashFunctionSize.Bits256: result = Sha3.Sha3256().ComputeHash(Encoding.UTF8.GetBytes(message)); break; case HashFunctionSize.Bits384: result = Sha3.Sha3384().ComputeHash(Encoding.UTF8.GetBytes(message)); break; case HashFunctionSize.Bits512: result = Sha3.Sha3512().ComputeHash(Encoding.UTF8.GetBytes(message)); break; } for (int i = 0; i < result.Length; i++) { hash.Append(result[i].ToString("x2")); } return(hash.ToString()); }
public static HEX Get_SHA3_Hash(string Text) { string temp = hashFunction; UInt16 security = Convert.ToUInt16(temp); return(Sha3.SHA3(Text, security)); }
public HMACChiko2(byte[] rgbKey) { HashSizeValue = 512; // Create the hash algorithms. hash1 = Sha3.Sha3512(); hash2 = Sha3.Sha3512(); // Get the key. if (rgbKey.Length > 128) { KeyValue = hash1.ComputeHash(rgbKey); // No need to call Initialize; ComputeHash does it automatically. } else { KeyValue = (byte[])rgbKey.Clone(); } // Compute rgbInner and rgbOuter. int i = 0; for (i = 0; i < 128; i++) { rgbInner[i] = 0x36; rgbOuter[i] = 0x5C; } for (i = 0; i < KeyValue.Length; i++) { rgbInner[i] ^= KeyValue[i]; rgbOuter[i] ^= KeyValue[i]; } }
public string ComputeHash(byte[] buffer) { var sha = Sha3.Sha3256(); var result = sha.ComputeHash(buffer); return(result.ToHex()); }
public string ComputeHash(string str) { var buffer = Encoding.ASCII.GetBytes(str); var sha = Sha3.Sha3256(); var result = sha.ComputeHash(buffer); return(result.ToHex()); }
static string GenerateId(string[] row) { var id = row[1] + row[2] + row[3]; using (var shaAlg = Sha3.Sha3256()) { return(Encoding.UTF8.GetString(shaAlg.ComputeHash(Encoding.UTF8.GetBytes(id)))); } }
public async Task <string> ComputeSha3OfObject(string path) { await using var dataStream = await GetObjectContent(path); var sha3 = Sha3.Sha3256(); var hash = await sha3.ComputeHashAsync(dataStream); return(Convert.ToHexString(hash).ToLowerInvariant()); }
public UsuarioModel(string primeiroNome, string ultimoNome, string nomeUsuario, string email, string endereco, int numero, string telefone, string senha) { PrimeiroNome = primeiroNome; UltimoNome = ultimoNome; NomeUsuario = nomeUsuario; Email = email; Endereco = endereco; Numero = numero; Telefone = telefone; _senha = Sha3.Sha3512().ComputeHash(Encoding.UTF8.GetBytes(string.Concat(senha, _salt))); }
public TicketScanResult CheckTicket(DigitalTicket scannedTicket, Ticket actualTicket) { if (scannedTicket is null) { throw new ArgumentNullException(nameof(scannedTicket), "Cannot check null ticket"); } if (!scannedTicket.Seat.Equals(actualTicket.Seat)) { throw new ArgumentException(nameof(actualTicket), "Seats do not match"); } byte[] scannedSecretHash; try { using var hasher = Sha3.Sha3224(); scannedSecretHash = hasher.ComputeHash(scannedTicket.Secret); } catch (ArgumentException e) { _logger.LogWarning(e.Message); return(null); } if (!actualTicket.Secret.SequenceEqual(scannedSecretHash)) { return(new TicketScanResult(false, string.Empty)); } if (actualTicket.CustomerIdentifier is null) { return(new TicketScanResult(true, string.Empty)); } string plainTextCustomerIdentifier; try { using var aes = _cipherFactory.CreateCbcProvider(); plainTextCustomerIdentifier = aes.Decrypt(actualTicket.CustomerIdentifier, scannedTicket.NameKey, scannedTicket.NameIV); } catch (CryptographicException e) { _logger.LogDebug(e.Message); return(new TicketScanResult(true, string.Empty)); } catch (ArgumentException e) { _logger.LogWarning(e.Message); return(null); } return(new TicketScanResult(true, plainTextCustomerIdentifier)); }
/// <summary> /// Faz o HASH SHA-3 da senha /// </summary> /// <param name="Password"></param> /// <returns></returns> internal string HashPassword(string Password) { StringBuilder x = new StringBuilder(); foreach (var item in Sha3.Sha3256().ComputeHash(Encoding.UTF8.GetBytes(Password))) { x.Append(item.ToString("x2")); } return(x.ToString()); }
public string CheckDigitalSignature(string hashToCheck, string plainText) { //string message = ConfigurationManager.AppSettings["Message"]; Sha3.ComputeHash(plainText); //string hashedMessage = GetHash(); if (Sha3.Hash.Equals(hashToCheck)) { return("Poruka je besprijekorna"); } return("Poruka nema integriteta"); }
public void ATest() { ECSigner ecSigner = new ECSigner("F43EBCC94E6C257EDBE559183D1A8778B2D5A08040902C0F0A77A3343A1D0EA5"); byte[] encoded = ecSigner._keyPair.ECPublicKey.Q.GetEncoded(); byte[] computeHash = Sha3.Sha3256().ComputeHash(encoded, 1, 64); string string2 = computeHash.ToHexString2(); String pubkey04 = "04e6a49d098ee94871252622b8a8b727e5cdf81b7138e5ac16591887f6e8c10e881e4b4250fa8c87f5b29ad020216a9ffd0acf5995a627d6c70e4dd274c54c20bd"; string hexString04 = Sha3.Sha3256().ComputeHash(pubkey04.FromHexToByteArray2(), 1, 64).ToHexString2(); }
/// <summary> /// Making SHA3-256 hash for password. /// </summary> /// <param name="input"> password in string </param> /// <returns> hash SHA3-256 </returns> public static byte[] ComputeHash(string input) { byte[] byteArray = Encoding.UTF32.GetBytes(input); MemoryStream stream = new MemoryStream(byteArray); var hash = Sha3.Sha3256().ComputeHash(stream); stream = new MemoryStream(hash); StreamReader rdr = new StreamReader(stream); string tst = rdr.ReadToEnd(); return(hash); }
/// <summary> /// Encrypting method using SHA-512 algorithm /// </summary> /// <param name="password">Password to encrypt</param> /// <returns>Encrypted password</returns> public String EncryptPassword(string password) { Sha3 sha512 = Sha3.Sha3512(); byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(password); byte[] hashBytes = sha512.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2").ToLower()); } return(sb.ToString()); }
public void CheckTicket_ProvidedSecretMatchesCustomerIdentifierDecrypted_ReturnsResultOwnsTicketNameMatchesDecryptedValue() { // Arrange var plainTextSecret = "f09aIm3-hH9379c"; byte[] hashedSecret; using (var hasher = Sha3.Sha3224()) { hashedSecret = hasher.ComputeHash(plainTextSecret); } var customerIdentifier = new byte[16] { 33, 93, 23, 252, 24, 38, 43, 94, 224, 10, 12, 232, 28, 211, 64, 99 }; var name = "Benjamin Swift"; var scannedTicket = new DigitalTicket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = plainTextSecret }; var actualTicket = new Ticket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = hashedSecret, CustomerIdentifier = customerIdentifier }; _cbc.Setup(callTo => callTo.Decrypt(customerIdentifier, It.IsAny <byte[]>(), It.IsAny <byte[]>())).Returns(name); // Act var result = _ticketChecker.CheckTicket(scannedTicket, actualTicket); // Assert Assert.Multiple(() => { Assert.That(result.OwnsTicket, Is.True, nameof(TicketScanResult.OwnsTicket)); Assert.That(result.Name, Is.EqualTo(name), nameof(TicketScanResult.Name)); }); }
public override string ToString() { var sha3Hash = Sha3.Sha3256().ComputeHash(Value); var sha3HashBytes = new byte[20]; Array.Copy(sha3Hash, sha3Hash.Length - 20, sha3HashBytes, 0, 20); var address = _addressPrefix + sha3HashBytes.ToHexString(); var hexToByteArray = address.FromHexToByteArray(); var hash = Sha256.HashTwice(hexToByteArray); var bytes = new byte[4]; Array.Copy(hash, bytes, 4); var checksum = bytes.ToHexString(); var addChecksum = (address + checksum).FromHexToByteArray(); Array.Copy(hexToByteArray, addChecksum, hexToByteArray.Length); return(Base58.Encode(addChecksum)); }
private static async Task <(TransactionInputData, TransactionModel)> Persist(string documentName, string text) { var request = new TransactionInputData() { DocumentName = documentName, Sha2 = SHA2_512(text), Sha3 = Sha3.Sha3512().ComputeHash(Encoding.UTF8.GetBytes(text)) }; var jsonToSend = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.None); var body = new StringContent(jsonToSend, Encoding.UTF8, "application/json"); var response = await client.PostAsync("/api/documents", body); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <TransactionModel>(data); return(request, result); }
public static string GetPasswordHash(string password) { if (password is null) { return(null); } using Sha3 sha3 = Sha3.Sha3512(); var hash = sha3.ComputeHash(Encoding.UTF8.GetBytes(password)); StringBuilder builder = new StringBuilder(); foreach (var b in hash) { builder.Append(b.ToString("x2")); } return(builder.ToString()); }
public void CheckTicket_ProvidedSecretMatchesDecryptCustomerIdentifierThrowsArgumentException_ReturnsNull() { // Arrange var plainTextSecret = "f09aIm3-hH9379c"; byte[] hashedSecret; using (var hasher = Sha3.Sha3224()) { hashedSecret = hasher.ComputeHash(plainTextSecret); } var customerIdentifier = new byte[16] { 33, 93, 23, 252, 24, 38, 43, 94, 224, 10, 12, 232, 28, 211, 64, 99 }; var scannedTicket = new DigitalTicket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = plainTextSecret }; var actualTicket = new Ticket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = hashedSecret, CustomerIdentifier = customerIdentifier }; _cbc.Setup(callTo => callTo.Decrypt(customerIdentifier, It.IsAny <byte[]>(), It.IsAny <byte[]>())).Throws <ArgumentException>(); // Act var result = _ticketChecker.CheckTicket(scannedTicket, actualTicket); // Assert Assert.That(result, Is.Null); }
public void CheckTicket_ProvidedSecretMatchesCustomerIdentifierNull_ReturnsResultOwnsTicketNameEmpty() { // Arrange var plainTextSecret = "f09aIm3-hH9379c"; byte[] hashedSecret; using (var hasher = Sha3.Sha3224()) { hashedSecret = hasher.ComputeHash(plainTextSecret); } var scannedTicket = new DigitalTicket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = plainTextSecret }; var actualTicket = new Ticket { Seat = new Seat { Number = 1, Letter = 'A' }, Secret = hashedSecret }; // Act var result = _ticketChecker.CheckTicket(scannedTicket, actualTicket); // Assert Assert.Multiple(() => { Assert.That(result.OwnsTicket, Is.True, nameof(TicketScanResult.OwnsTicket)); Assert.That(result.Name, Is.Empty, nameof(TicketScanResult.Name)); }); }
static void Main(string[] args) { Channel channel = new Channel("ac.testnet.libra.org:8000", ChannelCredentials.Insecure); var client = new AdmissionControl.AdmissionControl.AdmissionControlClient(channel); HexEncoder hex = new HexEncoder(); SharedSecret sharedSecret = SharedSecret.Import(Encoding.UTF8.GetBytes("newdummy")); HkdfSha512 kdf = new HkdfSha512(); var key = kdf.DeriveKey(sharedSecret, null, null, Ed25519.Ed25519); var sender = key.PublicKey.Export(KeyBlobFormat.RawPublicKey); UInt64 seqNum = 11; string senderHex = hex.EncodeData(Sha3.Sha3256().ComputeHash(sender)); uint amount = 10000000; string reciver = "4ba2555fd146e79e37fda7a2f30dc1b4f3d9228aa48b230dbab0a18d407f2f9b"; RawTransactionLCS rawTr = new RawTransactionLCS() { ExpirationTime = (ulong)DateTimeOffset.UtcNow.AddSeconds(60) .ToUnixTimeSeconds(), GasUnitPrice = 0, MaxGasAmount = 100000, SequenceNumber = seqNum }; rawTr.TransactionPayload = new TransactionPayloadLCS(); rawTr.TransactionPayload.PayloadType = (uint)TransactionPayloadLCSEnum.Script; rawTr.TransactionPayload.Script = new ScriptLCS() { Code = Utilities.PtPTrxBytecode, TransactionArguments = new List <TransactionArgumentLCS>() { new TransactionArgumentLCS() { ArgType = (uint)TransactionArgumentLCSEnum.Address, Address = new AddressLCS(reciver) }, new TransactionArgumentLCS() { ArgType = (uint)TransactionArgumentLCSEnum.U64, U64 = amount } } }; rawTr.Sender = new AddressLCS(senderHex); var bytesTrx = LCSCore.LCSSerialization(rawTr); Types.SignedTransaction signedTx = new Types.SignedTransaction(); var bytesTrxHash = Google.Protobuf.ByteString.CopyFrom(bytesTrx); var seed = Encoding.ASCII.GetBytes(RAWTX_HASH_SALT + LIBRA_HASH_SUFFIX); var seedHash = Sha3.Sha3256().ComputeHash(seed); List <byte> hashInput = new List <byte>(); hashInput.AddRange(seedHash); hashInput.AddRange(bytesTrxHash); var hash = Sha3.Sha3256().ComputeHash(hashInput.ToArray()); SubmitTransactionRequest req = new SubmitTransactionRequest(); req.SignedTxn = new SignedTransaction(); List <byte> retArr = new List <byte>(); retArr = retArr.Concat(bytesTrx).ToList(); retArr = retArr.Concat( LCSCore.LCSSerialization(key.Export(KeyBlobFormat.RawPublicKey))).ToList(); var sig = SignatureAlgorithm.Ed25519.Sign(key, hash); retArr = retArr.Concat(LCSCore.LCSSerialization(sig)).ToList(); req.SignedTxn.SignedTxn = ByteString.CopyFrom(retArr.ToArray()); var result = client.SubmitTransaction( req, new Metadata()); Task.Delay(5000).Wait(); GetTransaction(client, senderHex, seqNum); }
public static HEX Get_SHA3_Hash(FileStream fs) { UInt16 security = Convert.ToUInt16(hashFunction.Substring(hashFunction.Length - 3, 3)); return(Sha3.SHA3(fs, security)); }
/// <summary> /// Computes the hash value for the specified string /// </summary> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ObjectDisposedException"></exception> public static byte[] ComputeHash(this Sha3 hasher, string value) { return(hasher.ComputeHash(Encoding.UTF8.GetBytes(value))); }
public void HashSize_Returns_The_Correct_Value(int size) { var hash = new Sha3(size); hash.HashSize.Should().Be(size); }
public void Sha3512ComputeHash_WithControlledInput_ResultMatchesExpected(string input, string expected) { var hash = Sha3.Sha3512().ComputeHash(Encoding.UTF8.GetBytes(input)); hash.ToHexString().Should().Be(expected); }