• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encryption and Decryption Using JNCryptor  RSS feed

Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys

I'm making an application which will use encrypt data password from iOS , Now I need to decrypt password and validate password in java server code,
So for Encryption and Decryption I'm using JNCryptor , uses link https://github.com/RNCryptor/JNCryptor
Note : Encrypt data is working and I'm getting problem with decryptData.
Here below I shared code,

public class SecurityJNCryptor {

byte[] salt = new String("12345678").getBytes();
static final String HMAC_ALGORITHM = "HmacSHA256";
byte[] hmac = new String(HMAC_ALGORITHM).getBytes();
static String pass = "Java@123";
SecretKey decryptionKey;
SecretKey hmacKey;

public SecurityJNCryptor() throws InvalidKeySpecException, CryptorException{
AES256JNCryptor aesCiphertext = new AES256JNCryptor();
decryptionKey = aesCiphertext.keyForPassword(pass.toCharArray(), salt);
hmacKey = aesCiphertext.keyForPassword(pass.toCharArray(), hmac);


public String encriptorData(String password){
byte [] cipher = null;
String base64EncryptedData = null;
AES256JNCryptor cryptor = new AES256JNCryptor();
byte[] plaintext = "Hello , World!".getBytes();
cipher = cryptor.encryptData(plaintext, password.toCharArray());
base64EncryptedData = new sun.misc.BASE64Encoder().encodeBuffer(cipher);
System.out.println("Encrypted Data " + base64EncryptedData);

}catch(CryptorException exception){

return base64EncryptedData;


public String decryptData(String data) throws InvalidHMACException, CryptorException{
byte [] cipher = null;
AES256JNCryptor cryptor = new AES256JNCryptor();
cipher = cryptor.decryptData(data.getBytes(), decryptionKey , hmacKey);
return Base64.encode(cipher);


public static void main(String[] args) throws InvalidKeySpecException, InvalidHMACException, CryptorException {
SecurityJNCryptor decryptor = new SecurityJNCryptor();
String a = decryptor.encriptorData(pass);
String b = decryptor.decryptData(a);


while running this code I'm getting below exception.
Exception in thread "main" java.lang.IllegalArgumentException: Salt value must be 8 bytes.
at org.cryptonode.jncryptor.Validate.isTrue(Validate.java:27)
at org.cryptonode.jncryptor.AES256JNCryptor.keyForPassword(AES256JNCryptor.java:156)
at com.playstore.util.SecurityJNCryptor.<init>(SecurityJNCryptor.java:27)
at com.playstore.util.SecurityJNCryptor.main(SecurityJNCryptor.java:59)

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!