@@ -299,9 +299,11 @@ Encrypts a `Readable` stream to a `Writable` stream.
299
299
300
300
<summary >Returns</summary >
301
301
302
- Type: ` Promise<void> `
302
+ Type: ` Cph.Stream.Symmetric.EncryptReturnType `
303
303
304
- - A new Promise that resolves when the stream encryption is complete.
304
+ - An object containing:
305
+ - a new instance of ` crypto.Cipher ` allowing you to add listeners to the ` cipher ` encryption process.
306
+ - the actual ` encrypt ` callback that must be called and awaited in order to start the encryption process.
305
307
306
308
</details >
307
309
@@ -335,9 +337,11 @@ Decrypts a `Readable` stream to a `Writable` stream.
335
337
336
338
<summary >Returns</summary >
337
339
338
- Type: ` Promise<void > `
340
+ Type: ` Promise<Cph.Stream.Symmetric.DecryptReturnType > `
339
341
340
- - A new Promise that resolves when the stream decryption is complete.
342
+ - A new Promise that resolves when Key IV extraction completes returning an object containing:
343
+ - a new instance of ` crypto.Decipher ` allowing you to add listeners to the ` decipher ` decryption process.
344
+ - the actual ` decrypt ` callback that must be called and awaited in order to start the decryption process.
341
345
342
346
</details >
343
347
@@ -372,9 +376,11 @@ Encrypts a stream using hybrid encryption (symmetric + RSA).
372
376
373
377
<summary >Returns</summary >
374
378
375
- Type: ` Promise<void> `
379
+ Type: ` Cph.Stream.Hybrid.EncryptReturnType `
376
380
377
- - A new Promise that resolves when hybrid encryption is complete.
381
+ - An object containing:
382
+ - a new instance of ` cipher ` allowing you to add listeners to the ` cipher ` encryption process.
383
+ - the actual ` encrypt ` callback that must be called and awaited to start the encryption process.
378
384
379
385
</details >
380
386
@@ -408,9 +414,11 @@ Decrypts a stream using hybrid decryption (symmetric + RSA).
408
414
409
415
<summary >Returns</summary >
410
416
411
- Type: ` Promise<void > `
417
+ Type: ` Promise<Cph.Stream.Hybrid.DecryptReturnType > `
412
418
413
- - A new Promise that resolves when hybrid decryption is complete.
419
+ - A new Promise that resolves when Key IV extraction completes returning an object containing:
420
+ - a new instance of ` crypto.Decipher ` allowing you to add listeners to the ` decipher ` decryption process.
421
+ - the actual ` decrypt ` callback that must be called and awaited in order to start the decryption process.
414
422
415
423
</details >
416
424
@@ -496,6 +504,23 @@ Stream symmetric encryption options.
496
504
497
505
---
498
506
507
+ ##### ` Cph.Stream.Symmetric.EncryptReturnType `
508
+
509
+ Returnign object from ` Cipher.streamEncrypt() ` method.
510
+
511
+ <details >
512
+
513
+ <summary >Properties</summary >
514
+
515
+ | Property | Type | Description |
516
+ | ----------| ----------| -------------|
517
+ | ` cipher ` | ` crypto.Cipher ` | The ` crypto.Cipher ` instance. |
518
+ | ` encrypt ` | ` () => Promise<void> ` | The actual ` encrypt ` callback that must be called and awaited in order to start the encryption process. |
519
+
520
+ </details >
521
+
522
+ ---
523
+
499
524
##### ` Cph.Stream.Symmetric.DecryptOptions `
500
525
501
526
Stream symmetric decryption options.
@@ -515,6 +540,23 @@ Stream symmetric decryption options.
515
540
516
541
---
517
542
543
+ ##### ` Cph.Stream.Symmetric.DecryptReturnType `
544
+
545
+ Returnign object from awaited ` Cipher.streamDecrypt() ` method.
546
+
547
+ <details >
548
+
549
+ <summary >Properties</summary >
550
+
551
+ | Property | Type | Description |
552
+ | ----------| ----------| -------------|
553
+ | ` decipher ` | ` crypto.Decipher ` | The ` crypto.Decipher ` instance. |
554
+ | ` decrypt ` | ` () => Promise<void> ` | The actual ` decrypt ` callback that must be called and awaited in order to start the decryption process. |
555
+
556
+ </details >
557
+
558
+ ---
559
+
518
560
##### ` Cph.Stream.Hybrid.EncryptOptions `
519
561
520
562
Stream hybrid encryption options.
@@ -523,6 +565,14 @@ Stream hybrid encryption options.
523
565
524
566
---
525
567
568
+ ##### ` Cph.Stream.Hybrid.EncryptReturnType `
569
+
570
+ Returnign object from ` Cipher.hybridEncrypt() ` method.
571
+
572
+ - Alias for [ ` Cph.Stream.Symmetric.EncryptReturnType ` ] ( #cphstreamsymmetricencryptreturntype )
573
+
574
+ ---
575
+
526
576
##### ` Cph.Stream.Hybrid.DecryptOptions `
527
577
528
578
Stream hybrid decryption options.
@@ -541,6 +591,14 @@ Stream hybrid decryption options.
541
591
542
592
---
543
593
594
+ ##### ` Cph.Stream.Hybrid.DecryptReturnType `
595
+
596
+ Returnign object from awaited ` Cipher.hybridDecrypt() ` method.
597
+
598
+ - Alias for [ ` Cph.Stream.Symmetric.DecryptReturnType ` ] ( #cphstreamsymmetricdecryptreturntype )
599
+
600
+ ---
601
+
544
602
### Examples
545
603
546
604
#### Importing the library
@@ -609,6 +667,7 @@ const routeHandler = () => {
609
667
} )
610
668
611
669
Cipher .streamEncrypt ( password , { input , output } )
670
+ .encrypt ()
612
671
613
672
return (
614
673
// encrypted stream
@@ -664,7 +723,9 @@ const routeHandler = () => (
664
723
},
665
724
} )
666
725
667
- Cipher .streamDecrypt ( password , { input , output } )
726
+ const { decrypt } = await Cipher .streamDecrypt ( password , { input , output } )
727
+
728
+ decrypt ()
668
729
669
730
return (
670
731
// decrypted stream
@@ -729,12 +790,13 @@ const output = new Writable( {
729
790
}
730
791
} )
731
792
732
- await Cipher .hybridEncrypt ( password , {
793
+ const { encrypt } = Cipher .hybridEncrypt ( password , {
733
794
key : keyPair .publicKey ,
734
795
padding : crypto .constants .RSA_PKCS1_OAEP_PADDING ,
735
796
oaepHash : ' SHA-256' ,
736
797
}, { input , output } )
737
798
799
+ await encrypt ()
738
800
```
739
801
740
802
---
@@ -762,7 +824,7 @@ const output = new Writable( {
762
824
},
763
825
} )
764
826
765
- await Cipher .hybridDecrypt (
827
+ const { decrypt } = await Cipher .hybridDecrypt (
766
828
{
767
829
key : keyPair .privateKey ,
768
830
passphrase: password , // optional passhrase (required if set while generating keypair).
@@ -771,6 +833,8 @@ await Cipher.hybridDecrypt(
771
833
}, { input , output , rsaKeyLength }
772
834
)
773
835
836
+ await decrypt ()
837
+
774
838
console .log ( Buffer .concat ( chunks ).toString () ) // Outputs: 'my top-secret data'
775
839
```
776
840
@@ -793,6 +857,7 @@ const input = fs.createReadStream( 'my-very-large-top-secret-file.pdf' )
793
857
const output = fs .createWriteStream ( ' my-very-large-top-secret-file.encrypted' )
794
858
// encrypt
795
859
await Cipher .streamEncrypt ( password , { input , output } )
860
+ .encrypt ()
796
861
```
797
862
798
863
---
@@ -809,7 +874,8 @@ const input = fs.createReadStream( 'my-very-large-top-secret-file.encrypted' )
809
874
// output where decrypted data is written
810
875
const output = fs .createWriteStream ( ' my-very-large-top-secret-file-decrypted.pdf' )
811
876
// decrypt
812
- await Cipher .streamDecrypt ( password , { input , output } )
877
+ const { decrypt } = await Cipher .streamDecrypt ( password , { input , output } )
878
+ await decrypt ()
813
879
```
814
880
815
881
---
@@ -852,11 +918,12 @@ const input = fs.createReadStream( 'my-very-large-top-secret-file.pdf' )
852
918
// output where encrypted data is written
853
919
const output = fs .createWriteStream ( ' my-very-large-top-secret-file.encrypted' )
854
920
// encrypt
855
- await Cipher .hybridEncrypt ( password , {
921
+ const { encrypt } = Cipher .hybridEncrypt ( password , {
856
922
key : keyPair .publicKey ,
857
923
padding : crypto .constants .RSA_PKCS1_OAEP_PADDING ,
858
924
oaepHash : ' SHA-256' ,
859
925
}, { input , output } )
926
+ await encrypt ()
860
927
```
861
928
862
929
---
@@ -873,7 +940,7 @@ const input = fs.createReadStream( 'my-very-large-top-secret-file.encrypted' )
873
940
// output where decrypted data is written
874
941
const output = fs .createWriteStream ( ' my-very-large-top-secret-file-decrypted.pdf' )
875
942
// decrypt
876
- await Cipher .hybridDecrypt (
943
+ const { decrypt } = await Cipher .hybridDecrypt (
877
944
{
878
945
key : keyPair .privateKey ,
879
946
passphrase: password , // optional passhrase (required if set while generating keypair).
0 commit comments