|
1 | | -const wolfcrypt = require('./build/Release/wolfcrypt'); |
| 1 | +//const wolfcrypt = require('./build/Release/wolfcrypt'); |
| 2 | +const { WolfSSLDecryptor } = require( './WolfSSLDecryptor.ts' ) |
2 | 3 |
|
3 | | -let aes = Buffer.alloc( 300 ) |
| 4 | +/* |
| 5 | +let aes = Buffer.alloc( 1152 ) |
4 | 6 | let key = Buffer.from( '12345678901234567890123456789012' ) |
5 | 7 | let iv = Buffer.from( '1234567890123456' ) |
6 | 8 | let plainText = Buffer.from( 'testtesttesttest' ) |
7 | 9 | let cipherText = Buffer.alloc( 16 ) |
8 | 10 | let plainAgain = Buffer.alloc( 16 ) |
| 11 | +let length = 16 |
9 | 12 |
|
10 | 13 | let ret = wolfcrypt.MakeAes( aes, key, iv ) |
11 | 14 |
|
12 | 15 | if ( ret == 0 ) |
| 16 | + ret = wolfcrypt.Encrypt( aes, cipherText, plainText, length ) |
| 17 | +
|
| 18 | +if ( ret == 0 ) |
| 19 | + ret = wolfcrypt.Decrypt( aes, plainAgain, cipherText, length ) |
| 20 | +
|
| 21 | +console.log( plainText.toString() ) |
| 22 | +console.log( cipherText.toString( 'hex' ) ) |
| 23 | +console.log( plainAgain.toString() ) |
| 24 | +*/ |
| 25 | +/* |
| 26 | +let length = 0 |
| 27 | +let finalOutput = [] |
| 28 | +const key = Buffer.from('12345678901234567890123456789012') |
| 29 | +const iv = Buffer.from('1234567890123456'); |
| 30 | +
|
| 31 | +console.log( wolfcrypt.GetDecryptionSize() ) |
| 32 | +
|
| 33 | +let decryption = Buffer.alloc( wolfcrypt.GetDecryptionSize() ) |
| 34 | +wolfcrypt.NewDecryption( decryption, 'AES-256-CBC', key, iv ) |
| 35 | +
|
| 36 | +let outBuf = Buffer.alloc( 8 ) |
| 37 | +length = wolfcrypt.UpdateCipher( decryption, outBuf, Buffer.from('24d31b1e41fc8c40', 'hex'), 8 ) |
| 38 | +console.log( length ) |
| 39 | +
|
| 40 | +if ( length > 0 ) |
13 | 41 | { |
14 | | - ret = wolfcrypt.Encrypt( aes, cipherText, plainText, 16 ) |
| 42 | + finalOutput.push( outBuf ) |
15 | 43 | } |
16 | 44 |
|
17 | | -if ( ret == 0 ) |
| 45 | +outBuf = Buffer.alloc( 8 ) |
| 46 | +length = wolfcrypt.UpdateCipher( decryption, outBuf, Buffer.from('e521531d67c72c20', 'hex'), 8 ) |
| 47 | +console.log( length ) |
| 48 | +
|
| 49 | +if ( length > 0 ) |
| 50 | +{ |
| 51 | + finalOutput.push( outBuf ) |
| 52 | +} |
| 53 | +
|
| 54 | +outBuf = Buffer.alloc( 16 ) |
| 55 | +length = wolfcrypt.FinalizeCipher( decryption, outBuf ) |
| 56 | +console.log( length ) |
| 57 | +
|
| 58 | +if ( length > 0 ) |
18 | 59 | { |
19 | | - ret = wolfcrypt.Decrypt( aes, plainAgain, cipherText, 16 ) |
| 60 | + finalOutput.push( outBuf ) |
20 | 61 | } |
21 | 62 |
|
22 | | -console.log( plainText.toString() ); |
23 | | -console.log( cipherText.toString( 'hex' ) ); |
24 | | -console.log( plainAgain.toString() ); |
| 63 | +console.log( Buffer.concat( finalOutput ).toString() ) |
| 64 | +*/ |
| 65 | + |
| 66 | +const key = Buffer.from('12345678901234567890123456789012'); |
| 67 | +const iv = Buffer.from('1234567890123456'); |
| 68 | +const decrypt = new WolfSSLDecryptor('AES-256-CBC', key, iv); |
| 69 | +const expected = 'test'; |
| 70 | + |
| 71 | +const actual = Buffer.concat([ |
| 72 | + decrypt.update(Buffer.from('24d31b1e41fc8c40', 'hex')), |
| 73 | + decrypt.update(Buffer.from('e521531d67c72c20', 'hex')), |
| 74 | + decrypt.finalize() |
| 75 | +]); |
| 76 | + |
| 77 | +console.log( actual.toString() ) |
0 commit comments