123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package com.epson.mobilephone.common.keyenc;
- import android.content.Context;
- import android.util.Base64;
- import java.nio.charset.Charset;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.security.NoSuchProviderException;
- import javax.crypto.Cipher;
- import javax.crypto.NoSuchPaddingException;
- import javax.crypto.spec.SecretKeySpec;
- public class SecureKeyFactory {
- static SecureKeyFactory instance;
- private final String ENCRYPT_ALGORITHM = "AES";
- private final int ENCRYPT_KEY_BYTES = 16;
- private final String ENCRYPT_METHOD = "AES/ECB/PKCS5Padding";
- private final String ENCRYPT_PROVIDER = "AndroidOpenSSL";
- private final Charset charset = Charset.forName("UTF8");
- private byte[] key = null;
- protected Context mAppContext = null;
- String mSecurityProvider = "AndroidOpenSSL";
- private native byte[] navite_getAppKey(Context context);
- private native byte[] navite_getKey(Context context);
- protected SecureKeyFactory(Context context) {
- try {
- System.loadLibrary("keyenclib");
- } catch (Exception e) {
- e.printStackTrace();
- }
- mAppContext = context.getApplicationContext();
- key = navite_getKey(mAppContext);
- }
- public static SecureKeyFactory getInstance(Context context) {
- return getInstance(context, (String) null);
- }
- public static SecureKeyFactory getInstance(Context context, String str) {
- if (instance == null) {
- instance = new SecureKeyFactory(context);
- }
- if (str == null) {
- SecureKeyFactory secureKeyFactory = instance;
- secureKeyFactory.getClass();
- secureKeyFactory.mSecurityProvider = "AndroidOpenSSL";
- } else if (!instance.mSecurityProvider.equals(str)) {
- instance.mSecurityProvider = str;
- }
- return instance;
- }
- private Cipher getCipher() throws NoSuchPaddingException, NoSuchAlgorithmException {
- try {
- return Cipher.getInstance("AES/ECB/PKCS5Padding", mSecurityProvider);
- } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
- e.printStackTrace();
- return Cipher.getInstance("AES/ECB/PKCS5Padding");
- }
- }
- /* JADX WARNING: Code restructure failed: missing block: B:6:0x0018, code lost:
- r2 = android.util.Base64.encodeToString((r2 = encodeAes(r2.getBytes(r1.charset), r1.key)), 10);
- */
- /* Code decompiled incorrectly, please refer to instructions dump. */
- public java.lang.String Encode(java.lang.String r2) {
- /*
- r1 = this;
- byte[] r0 = r1.key
- if (r0 != 0) goto L_0x0007
- java.lang.String r2 = ""
- return r2
- L_0x0007:
- java.nio.charset.Charset r0 = r1.charset
- byte[] r2 = r2.getBytes(r0)
- byte[] r0 = r1.key
- byte[] r2 = r1.encodeAes(r2, r0)
- if (r2 != 0) goto L_0x0018
- java.lang.String r2 = ""
- return r2
- L_0x0018:
- r0 = 10
- java.lang.String r2 = android.util.Base64.encodeToString(r2, r0)
- if (r2 != 0) goto L_0x0023
- java.lang.String r2 = ""
- return r2
- L_0x0023:
- return r2
- */
- throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.keyenc.SecureKeyFactory.Encode(java.lang.String):java.lang.String");
- }
- public String Decode(String str) {
- byte[] decode;
- byte[] decodeAes;
- if (key == null || (decode = Base64.decode(str, 10)) == null || (decodeAes = decodeAes(decode, key)) == null) {
- return "";
- }
- return new String(decodeAes, charset);
- }
- private byte[] encodeAes(byte[] bArr, byte[] bArr2) {
- if (bArr == null || bArr2 == null) {
- return null;
- }
- try {
- byte[] makeKeyBytes = makeKeyBytes(16, bArr2);
- Cipher cipher = getCipher();
- cipher.init(1, new SecretKeySpec(makeKeyBytes, "AES"));
- return cipher.doFinal(bArr);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- private byte[] makeKeyBytes(int i, byte[] bArr) {
- byte[] bArr2 = new byte[i];
- for (int i2 = 0; i2 < bArr2.length; i2++) {
- if (i2 < bArr.length) {
- bArr2[i2] = bArr[i2];
- } else {
- bArr2[i2] = 0;
- }
- }
- return bArr2;
- }
- private byte[] decodeAes(byte[] bArr, byte[] bArr2) {
- if (bArr == null || bArr2 == null) {
- return null;
- }
- try {
- byte[] makeKeyBytes = makeKeyBytes(16, bArr2);
- Cipher cipher = getCipher();
- cipher.init(2, new SecretKeySpec(makeKeyBytes, "AES"));
- return cipher.doFinal(bArr);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public static byte[] getMd5(byte[] bArr) {
- byte[] bArr2 = {0};
- try {
- MessageDigest instance2 = MessageDigest.getInstance("MD5");
- instance2.update(bArr);
- return instance2.digest();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- return bArr2;
- }
- }
- }
|