what-the-bank/sources/com/kofax/kmc/klo/logistics/service/CryptoService.java

73 lines
2.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.klo.logistics.service;
import com.kofax.mobile.sdk._internal.k;
import java.security.MessageDigest;
import org.bouncycastle.pqc.jcajce.spec.McElieceCCA2KeyGenParameterSpec;
/* loaded from: classes3.dex */
public class CryptoService {
private static final String TAG = "CryptoService";
public static char convertIntToHexChar(int i) {
return (char) ((i < 0 || i > 9) ? i + 87 : i + 48);
}
public static String convertBytesToHex(byte[] bArr) {
StringBuffer stringBuffer = new StringBuffer();
for (byte b : bArr) {
stringBuffer.append(convertByteToHex(b).toUpperCase());
}
return stringBuffer.toString();
}
public static String convertByteToHex(byte b) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(convertIntToHexChar((b >>> 4) & 15));
stringBuffer.append(convertIntToHexChar(b & 15));
return stringBuffer.toString();
}
public static String md5Hash(String str) {
try {
return MessageDigest.getInstance("md5").digest(str.getBytes()).toString();
} catch (Exception e) {
String str2 = TAG;
StringBuilder sb = new StringBuilder("Error creating md5 hash for '");
sb.append(str);
sb.append("'");
k.e(str2, sb.toString(), (Throwable) e);
return null;
}
}
public static String sha256Hash(String str) {
try {
MessageDigest messageDigest = MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA256);
messageDigest.update(str.getBytes());
return convertBytesToHex(messageDigest.digest());
} catch (Exception e) {
String str2 = TAG;
StringBuilder sb = new StringBuilder("Error creating sha hash for '");
sb.append(str);
sb.append("'");
k.e(str2, sb.toString(), (Throwable) e);
return null;
}
}
public static String sha1Hash(String str) {
try {
MessageDigest messageDigest = MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA1);
messageDigest.update(str.getBytes());
return convertBytesToHex(messageDigest.digest());
} catch (Exception e) {
String str2 = TAG;
StringBuilder sb = new StringBuilder("Error creating sha hash for '");
sb.append(str);
sb.append("'");
k.e(str2, sb.toString(), (Throwable) e);
return null;
}
}
}