public static byte[] Encrypt(this IEncryptionMethod self, string inputString) { byte[] bytes; if (inputString.IsBase64()) { bytes = Convert.FromBase64String(inputString); } else { bytes = Fi.StandardEncoding.GetBytes(inputString); } return(self.Encrypt(bytes)); }
public async Task Process(Stream input, Func <Stream, Task> act) { using (MemoryStream ms = new MemoryStream()) { await input.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); var bytes = ms.ToArray(); var cypheredBytes = _method.Encrypt(bytes); using (MemoryStream output = new MemoryStream(cypheredBytes)) { await act(output); } } }
public static String EncryptToBase64(this IEncryptionMethod self, byte[] bytes) { return(Convert.ToBase64String(self.Encrypt(bytes))); }