diff --git a/node/node-tests.ts b/node/node-tests.ts index c944e168d..a8c13f8b0 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -113,6 +113,26 @@ function crypto_cipher_decipher_string_test() { assert.equal(clearText2, clearText); } +function crypto_cipher_decipher_buffer_test() { + var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]); + var clearText:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]); + var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key); + var cipherBuffers:Buffer[] = []; + cipherBuffers.push(cipher.update(clearText)); + cipherBuffers.push(cipher.final()); + + var cipherText:Buffer = Buffer.concat(cipherBuffers); + + var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key); + var decipherBuffers:Buffer[] = []; + decipherBuffers.push(decipher.update(cipherText)); + decipherBuffers.push(decipher.final()); + + var clearText2:Buffer = Buffer.concat(decipherBuffers); + + assert.deepEqual(clearText2, clearText); +} + //////////////////////////////////////////////////// // Make sure .listen() and .close() retuern a Server instance diff --git a/node/node.d.ts b/node/node.d.ts index 0293ebae2..caeaa3f41 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -1076,15 +1076,19 @@ declare module "crypto" { export function createCipher(algorithm: string, password: any): Cipher; export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; interface Cipher { - update(data: any, input_encoding?: string, output_encoding?: string): string; - final(output_encoding?: string): string; + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; setAutoPadding(auto_padding: boolean): void; } export function createDecipher(algorithm: string, password: any): Decipher; export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; interface Decipher { - update(data: any, input_encoding?: string, output_encoding?: string): string; - final(output_encoding?: string): string; + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; setAutoPadding(auto_padding: boolean): void; } export function createSign(algorithm: string): Signer;