英文:
What type of encryption that used in this?
问题
以下是您提供的代码的翻译:
static String encrypt(String text) throws Exception
{
String password = AppData.ENCRYPT_SERVER;
final byte[] pass = password.getBytes(US_ASCII);
final byte[] salt = (new SecureRandom()).generateSeed(8);
final byte[] inBytes = text.getBytes(UTF_8);
final byte[] passAndSalt = array_concat(pass, salt);
byte[] hash = new byte[0];
byte[] keyAndIv = new byte[0];
for (int i = 0; i < 3 && keyAndIv.length < 48; i++) {
final byte[] hashData = array_concat(hash, passAndSalt);
final MessageDigest md = MessageDigest.getInstance("MD5");
hash = md.digest(hashData);
keyAndIv = array_concat(keyAndIv, hash);
}
final byte[] keyValue = Arrays.copyOfRange(keyAndIv, 0, 32);
final byte[] iv = Arrays.copyOfRange(keyAndIv, 32, 48);
final SecretKeySpec key = new SecretKeySpec(keyValue, "AES");
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
byte[] data = cipher.doFinal(inBytes);
data = array_concat(array_concat(SALTED_MAGIC, salt), data);
return Base64.encodeToString(data, Base64.DEFAULT);
}
请注意,代码中引用的变量(如AppData.ENCRYPT_SERVER
、US_ASCII
、UTF_8
、SALTED_MAGIC
等)没有提供上下文,因此它们的含义可能需要您根据实际情况进行调整。另外,这段代码使用了AES加密算法进行文本加密。
英文:
I'm new on Mobile Programming especially encryption, is anyone know what type of encryption that used in this code below?
static String encrypt(String text) throws Exception
{
String password = AppData.ENCRYPT_SERVER;
final byte[] pass = password.getBytes(US_ASCII);
final byte[] salt = (new SecureRandom()).generateSeed(8);
final byte[] inBytes = text.getBytes(UTF_8);
final byte[] passAndSalt = array_concat(pass, salt);
byte[] hash = new byte[0];
byte[] keyAndIv = new byte[0];
for (int i = 0; i < 3 && keyAndIv.length < 48; i++) {
final byte[] hashData = array_concat(hash, passAndSalt);
final MessageDigest md = MessageDigest.getInstance("MD5");
hash = md.digest(hashData);
keyAndIv = array_concat(keyAndIv, hash);
}
final byte[] keyValue = Arrays.copyOfRange(keyAndIv, 0, 32);
final byte[] iv = Arrays.copyOfRange(keyAndIv, 32, 48);
final SecretKeySpec key = new SecretKeySpec(keyValue, "AES");
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
byte[] data = cipher.doFinal(inBytes);
data = array_concat(array_concat(SALTED_MAGIC, salt), data);
return Base64.encodeToString(data, Base64.DEFAULT);
}
答案1
得分: 1
你在这一行中找到了你的问题的答案:
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
AES
高级加密标准 - 这是您的加密方式。
CBC
密文分组链接 - 这是密码加密模式。
PKCS5
公钥密码学标准#5 - 这是所应用的填充。
英文:
You have the answer to your question in this line:
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
AES
Advanced Encryption Standard - this is your encryption.
CBC
Cipher block chaining - this is the cipher encryption mode.
PKCS5
Public Key Cryptography Standards #5 - This is the padding applied.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论