使用了什么类型的加密?

huangapple go评论70阅读模式
英文:

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_SERVERUS_ASCIIUTF_8SALTED_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 &lt; 3 &amp;&amp; keyAndIv.length &lt; 48; i++) {
            final byte[] hashData = array_concat(hash, passAndSalt);
            final MessageDigest md = MessageDigest.getInstance(&quot;MD5&quot;);
            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, &quot;AES&quot;);

        final Cipher cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5Padding&quot;);
        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(&quot;AES/CBC/PKCS5Padding&quot;);

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.

huangapple
  • 本文由 发表于 2020年8月31日 23:26:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63673673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定