public static string Encrypt(string plain, string sectret, string salt) { string result = null; //Schlüssel für crypt und hmac erzeugen byte[] hashBytes = null; string hash = Hashhelper.Hash((sectret + salt), out hashBytes, _encoding); // IV erzeugen 16 bytes lang int ivSize = 16; byte[] ivBytes = null; string iv = InitialisationVectorHelper.CreateInitialisationVextorStringWithOpenSSL(ivSize, out ivBytes, _encoding); // Verschlüsseln string encrypted = EncryptHelper.EncryptWithOpenSSLCrypt(plain, hashBytes, ivBytes, _encoding); string ciphertext = iv + encrypted; // HMAC erzeugen string hmac = HmacHelper.HashHmacWithOpenSSLSHA256(ciphertext, hashBytes, _encoding); //zusammenfügen dann zu hex umwandeln und fertig byte[] resultBytes = _encoding.GetBytes(hmac + ciphertext); result = HexHelper.GetHexFromBytes(resultBytes); return(result); }
public static string Hash(string data, out byte[] hashBytes, Encoding encoding) { string key = null; byte[] hashBytes2 = null; string hash = Hashhelper.HashWithSHA2561(data, ref hashBytes2, encoding); key = hash.Substring(0, 32); hashBytes = new byte[32]; hashBytes = encoding.GetBytes(key); return(key); }