@@ -20,7 +20,7 @@ private static TestFile SRC_FILE
20
20
}
21
21
}
22
22
23
- private static byte [ ] ENCRYPTED_BUFFER = Secrets . EncryptStringToBufferAsync ( SRC_STRING , PWD ) . Result ;
23
+ private static readonly byte [ ] ENCRYPTED_BUFFER = Secrets . EncryptStringToBufferAsync ( SRC_STRING , PWD ) . Result ;
24
24
private static Stream ENCRYPTED_STREAM => new MemoryStream ( ENCRYPTED_BUFFER ) ;
25
25
private static TestFile ENCRYPTED_FILE
26
26
{
@@ -32,35 +32,35 @@ private static TestFile ENCRYPTED_FILE
32
32
}
33
33
}
34
34
35
- private async Task CheckEncryptedAsync ( MemoryStream encrypted )
35
+ private static async Task CheckEncryptedAsync ( MemoryStream encrypted )
36
36
{
37
37
var decrypted = await Secrets . DecryptBufferToStringAsync ( encrypted . ToArray ( ) , PWD ) ;
38
38
Assert . True ( decrypted == SRC_STRING ) ;
39
39
}
40
- private async Task CheckEncryptedAsync ( byte [ ] encrypted )
40
+ private static async Task CheckEncryptedAsync ( byte [ ] encrypted )
41
41
{
42
42
var decrypted = await Secrets . DecryptBufferToStringAsync ( encrypted , PWD ) ;
43
43
Assert . True ( decrypted == SRC_STRING ) ;
44
44
}
45
- private async Task CheckEncryptedAsync ( TestFile encrypted )
45
+ private static async Task CheckEncryptedAsync ( TestFile encrypted )
46
46
{
47
47
var decrypted = await Secrets . DecryptFileToStringAsync ( encrypted . Path , PWD ) ;
48
48
Assert . True ( decrypted == SRC_STRING ) ;
49
49
}
50
50
51
- private void CheckDecrypted ( string decrypted )
51
+ private static void CheckDecrypted ( string decrypted )
52
52
{
53
53
Assert . True ( decrypted == SRC_STRING ) ;
54
54
}
55
- private void CheckDecryptedAsync ( MemoryStream decrypted )
55
+ private static void CheckDecryptedAsync ( MemoryStream decrypted )
56
56
{
57
57
CheckDecrypted ( decrypted . ToArray ( ) ) ;
58
58
}
59
- private void CheckDecrypted ( byte [ ] decrypted )
59
+ private static void CheckDecrypted ( byte [ ] decrypted )
60
60
{
61
61
CheckDecrypted ( Encoding . UTF8 . GetString ( decrypted ) ) ;
62
62
}
63
- private void CheckDecrypted ( TestFile decrypted )
63
+ private static void CheckDecrypted ( TestFile decrypted )
64
64
{
65
65
var s = File . ReadAllText ( decrypted . Path ) ;
66
66
Assert . True ( s == SRC_STRING ) ;
@@ -328,5 +328,34 @@ public async Task Roundtrip_UrlEncodedBase64()
328
328
329
329
Assert . True ( plaintext0 == plaintext1 ) ;
330
330
}
331
+
332
+
333
+
334
+ [ Fact ]
335
+ public async Task RoundTrip_Large_File ( )
336
+ {
337
+ var sourceFile = Path . GetFullPath ( @"../../../../../data/image.jpg" ) ;
338
+ var encryptedFile = sourceFile + ".encrypted" ;
339
+ var decryptedFile = sourceFile + ".decrypted.jpg" ;
340
+
341
+ try
342
+ {
343
+ await Secrets . EncryptFileToFileAsync ( sourceFile , encryptedFile , "password" ) ;
344
+ await Secrets . DecryptFileToFileAsync ( encryptedFile , decryptedFile , "password" ) ;
345
+
346
+ var buffer0 = File . ReadAllBytes ( sourceFile ) ;
347
+ var buffer1 = File . ReadAllBytes ( decryptedFile ) ;
348
+ Assert . True ( buffer0 . Length == buffer1 . Length ) ;
349
+ for ( var i = 0 ; i < buffer0 . Length ; i ++ )
350
+ {
351
+ if ( buffer0 [ i ] != buffer1 [ i ] ) Assert . Fail ( "Decrypted file is not identical to original file." ) ;
352
+ }
353
+ }
354
+ finally
355
+ {
356
+ File . Delete ( encryptedFile ) ;
357
+ File . Delete ( decryptedFile ) ;
358
+ }
359
+ }
331
360
}
332
361
}
0 commit comments