Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nissan Connect API encryption using Java
package me.netlift.mobile.activities;
import android.util.Base64;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class NissanConnectEncryption {
public static String doEncrypt(String paramString)
{
String basePRM = "uyI5Dj9g8VCOFDnBRUbr3g";
return cipherEncrypt(paramString.getBytes(), basePRM);
}
private static String cipherEncrypt(byte[] paramArrayOfByte, String paramString)
{
try
{
Key key = new SecretKeySpec(paramString.getBytes(), "Blowfish");
Cipher localCipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
localCipher.init(1, key);
paramArrayOfByte = localCipher.doFinal(paramArrayOfByte);
return Base64.encodeToString(paramArrayOfByte, 0);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return null;
}
}
@francos

This comment has been minimized.

Copy link

@francos francos commented Aug 30, 2018

Thanks for the code @gboudreau, it saved me a lot of time of try and error 👍

I used it to encrypt the user's password to call the Nissan login API. For anyone who is trying to use the same, paramString should be the password value when calling doEncrypt().

Also, a couple of clarifications of the ints in the code:

// 1 is ENCRYPT_MODE
localCipher.init(1, key);

// You can use this call instead:
localCipher.init(ENCRYPT_MODE, key);
// 0 is DEFAULT
return Base64.encodeToString(paramArrayOfByte, 0);

// You can use this call instead:
return Base64.encodeToString(paramArrayOfByte, DEFAULT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.