private static async Task PiecewiseEncryptionAsync(string inFile, string outFile, IUbiqCredentials ubiqCredentials) { using (var plainStream = new FileStream(inFile, FileMode.Open)) { using (var cipherStream = new FileStream(outFile, FileMode.Create)) { using (var ubiqEncrypt = new UbiqEncrypt(ubiqCredentials, 1)) { var cipherBytes = await ubiqEncrypt.BeginAsync(); cipherStream.Write(cipherBytes, 0, cipherBytes.Length); var plainBytes = new byte[0x20000]; int bytesRead = 0; while ((bytesRead = plainStream.Read(plainBytes, 0, plainBytes.Length)) > 0) { cipherBytes = ubiqEncrypt.Update(plainBytes, 0, bytesRead); cipherStream.Write(cipherBytes, 0, cipherBytes.Length); } cipherBytes = ubiqEncrypt.End(); cipherStream.Write(cipherBytes, 0, cipherBytes.Length); } } } }
private static async Task SimpleEncryptionAsync(string inFile, string outFile, IUbiqCredentials ubiqCredentials) { var plainBytes = File.ReadAllBytes(inFile); var cipherBytes = await UbiqEncrypt.EncryptAsync(ubiqCredentials, plainBytes); File.WriteAllBytes(outFile, cipherBytes); }