File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,20 +4,26 @@ var base64 = require('urlsafe-base64');
44var crypto = require ( 'crypto' ) ;
55var ece = require ( './ece.js' ) ;
66
7- if ( process . argv . length < 6 ) {
7+ if ( process . argv . length < 7 ) {
88 console . warn ( 'Usage: ' + process . argv . slice ( 0 , 2 ) . join ( ' ' ) +
9- ' <receiver-private> <sender-public> <salt> <message>' ) ;
9+ ' <receiver-private> <receiver-public> < sender-public> <salt> <message>' ) ;
1010 process . exit ( 2 ) ;
1111}
1212
1313var receiver = crypto . createECDH ( 'prime256v1' ) ;
14+ // node crypto is finicky about accessing the public key
15+ // 1. it can't generate the public key from the private key
16+ // 2. it barfs when you try to access the public key, even after you set it
17+ // This hack squelches the complaints at the cost of a few wasted cycles
18+ receiver . generateKeys ( ) ;
19+ receiver . setPublicKey ( base64 . decode ( process . argv [ 3 ] ) ) ;
1420receiver . setPrivateKey ( base64 . decode ( process . argv [ 2 ] ) ) ;
15- ece . saveKey ( 'keyid' , receiver ) ;
21+ ece . saveKey ( 'keyid' , receiver , "P-256" ) ;
1622
17- var result = ece . decrypt ( base64 . decode ( process . argv [ 5 ] ) , {
23+ var result = ece . decrypt ( base64 . decode ( process . argv [ 6 ] ) , {
1824 keyid : 'keyid' ,
19- dh : process . argv [ 3 ] ,
20- salt : process . argv [ 4 ]
25+ dh : process . argv [ 4 ] ,
26+ salt : process . argv [ 5 ]
2127} ) ;
2228
2329console . log ( base64 . encode ( result ) ) ;
You can’t perform that action at this time.
0 commit comments