Javascript/NodeJS equivalent code for the Java code Cipher.doFinal(byte[])?

Omnipotence

I am migrating some server-side Java code to a new NodeJS server. I am looking for an equivalent method call in Javascript to Java's Cipher.doFinal(byte[]) Note that I can't use NodeJS Buffers because they don't support negative Byte values. So to do my encryption, I'll need a method that accepts an array of positive and negative numbers.

Here's all of what I currently have that is related to this problem:

Node JS / Javascript:
var crypto = require('crypto'); var cipher = crypto.createCipher('aes256',key);

Java (javax.crypto.Cipher):

Cipher cipher;
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
try {
    cipher = Cipher.getInstance("AES");
} catch (NoSuchAlgorithmException e) {
} catch (NoSuchPaddingException e) {
}try {
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
} catch (InvalidKeyException e) {
}

later in the Java code, I call this method where Iv represents Initialization Vector: byte[] newIv = cipher.doFinal(myIv);

How can I get the same result in JavaScript as I do in the doFinal Java method?

Omnipotence

Turns out you can place an empty IV as follows:

var cipher = require('crypto').createCipheriv('aes-256'ecb', key, '');

As for the replacement method, simply store your old IV temporarily as a new IV and then attempt to update that new IV using the old one. Here's how it would look like in NodeJS using some of the above code on Initialization Vectors created as buffers:
var newIV = oldIV.slice(); newIV = cipher.update(newIV); oldIV = newIV;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Java equivalent of PHP code return different base 64 encoding result

From Dev

C# Equivalent to this code

From Dev

Java equivalent of #ifdef that allows non-compilable code

From Dev

need help translating a code snippet from java to C# equivalent

From Dev

Haskell equivalent of this Python code

From Dev

Matlab equivalent code for file

From Dev

What is the equivalent of this snippet of Java code in C#?

From Dev

How to get the actual block cipher key size for Java SSL connection _in code_?

From Dev

What is the Java equivalent of this Scala code?

From Dev

Are these lines of JavaScript code equivalent?

From Dev

Is this Haskell code equivalent to this Python code?

From Dev

%timeit equivalent in code

From Dev

What is this Java code equivalent in C# ? (setRequestEntity)

From Dev

How can I shorten this substitution cipher code?

From Dev

Equivalent code in IronPython

From Dev

Does this code qualify to be a block cipher

From Dev

C# Equivalent to this code

From Dev

Equivalent java code statement for C code statement used in recursion

From Dev

Matlab equivalent code for file

From Dev

Python string concatation for Caesar cipher, comparable with Java code

From Dev

sed equivalent code for AIX

From Dev

Is this Haskell code equivalent to this Python code?

From Dev

Equivalent code without the library

From Dev

What is this Java code equivalent in C# ? (setRequestEntity)

From Dev

Is this Swift code equivalent?

From Dev

Equivalent Scala code for Java code

From Dev

How to ignore spaces in Vigenere cipher code?

From Dev

Is this Python code equivalent of Java code?

From Dev

What is the code equivalent to this css code?

Related Related

HotTag

Archive