How to Code Encryption Algorithm in Java?

How do I write the below encryption Java code in Node.js?

  • Hi, I am moving my current application for some reason to Node.js (I like it). But moving encryption part is becoming difficult. Can anyone provide solution for this. I have tried but no luck always the encryption generated is wrong in Node.js when compared to Java. I have checked node.js crypto document but no luck. //SecretKeySpec creation code. SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); PBEKeySpec keySpec = new PBEKeySpec("myEncyptKey".toCharArray(),"myCryptSalt".getBytes(CharEncoding.UTF_8), 65536, 256); SecretKeySpec  secretKeySpec = new SecretKeySpec(factory.generateSecret(keySpec).getEncoded(), "AES"); //Encryption code Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding"); aes.init(Cipher.ENCRYPT_MODE, secretKeySpec); byte[] encrypted = aes.doFinal(plainText.getBytes(CharEncoding.UTF_8));

  • Answer:

    respected, i a m not expert in java(i'm beginner) but in node.js , however i have used file encryption/encryption in node.js for my project, have a look for encrypt/decrypt file : http://www.i-visionblog.com/2014/08/file-encryptor-nodejs-module.html for string values : https://gist.github.com/csanz/1181250 This is just basics for simple encryption,if u have openssl installed you can try out other algorithm! for any errors pls let me know!

S Shiva Surya at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.