/// <summary> /// Encodes a byte array of data. /// </summary> /// <param name="data">The data to encode.</param> /// <param name="unusedKey">Unused by the <see cref="MachineCrypto"/>.</param> /// <returns>The encoded data.</returns> public byte[] Encode(byte[] data, byte[] unusedKey) { // Calculate the header (hash of the decrypted data) var header = Hasher.GetHash(data); // Encrypt the data var encData = _crypt.Encode(data, Key); // Join the header and encrypted data var joinedData = new byte[encData.Length + _headerBytes]; Buffer.BlockCopy(header, 0, joinedData, 0, Math.Min(header.Length, _headerBytes)); encData.CopyTo(joinedData, _headerBytes); // Return the joined data return(joinedData); }
public static string EncodeToBase64(this ISimpleCryptoProvider c, byte[] data, byte[] key) { var encBytes = c.Encode(data, key); return(CryptoHelper.BytesToString64(encBytes)); }
public static byte[] Encode(this ISimpleCryptoProvider c, string data, byte[] key) { var bytes = CryptoHelper.StringToBytes(data); return(c.Encode(bytes, key)); }