吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1429|回复: 2
收起左侧

[Android 求助] 请教这个怎么算出IV

[复制链接]
qzbbs 发表于 2020-2-13 10:28
本帖最后由 qzbbs 于 2020-2-13 10:30 编辑

package com.base.utils.http.impl;

import java.io.PrintStream;
import java.net.URLEncoder;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public final class a
{
  static byte[] a = { 85, 60, 12, 116, 99, -67, -83, 19, -118, -73, -24, -8, 82, -24, -56, -14 };
  static String b = "china1233_aeskey";

  public static String Decrypt(String paramString1, String paramString2)
  {
    if (paramString2 == null)
    {
      System.out.print("Key为空null");
      return null;
    }
    if (paramString2.length() != 16)
    {
      System.out.print("Key长度不是16位");
      return null;
    }
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramString2.getBytes("ASCII"), "AES");
    Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    localCipher.init(2, localSecretKeySpec, new IvParameterSpec(a));
    return new String(localCipher.doFinal(b.decode(paramString1, 0)));
  }

  public static String Encrypt(String paramString)
  {
    if (b == null)
    {
      System.out.print("Key为空null");
      return null;
    }
    if (b.length() != 16)
    {
      System.out.print("Key长度不是16位");
      return null;
    }
    System.out.println("------加密-----------");
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(b.getBytes(), "AES");
    Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    localCipher.init(1, localSecretKeySpec, new IvParameterSpec(a));
    return b.encodeToString(localCipher.doFinal(paramString.getBytes("UTF-8")), 0);
  }

  public static void main(String[] paramArrayOfString)
  {
    System.out.println("加密前:" + "AAAAAABBBBBBCCCCC");
    long l1 = System.currentTimeMillis();
    try
    {
      String str1 = Encrypt("AAAAAABBBBBBCCCCC");
      System.out.println("密文是:" + str1);
      long l2 = System.currentTimeMillis() - l1;
      System.out.println("加密耗时:" + l2 + "毫秒");
      System.out.println("密文URLEncode后是:" + URLEncoder.encode(str1, "UTF-8"));
      long l3 = System.currentTimeMillis();
      String str2 = Decrypt(str1, b);
      System.out.println("解密后的明文是:" + str2);
      long l4 = System.currentTimeMillis() - l3;
      System.out.println("解密耗时:" + l4 + "毫秒");
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ps122 发表于 2020-2-13 11:18
new IvParameterSpec(a)
static byte[] a = { 85, 60, 12, 116, 99, -67, -83, 19, -118, -73, -24, -8, 82, -24, -56, -14 };
这不很明显了吗,还求啥

 楼主| qzbbs 发表于 2020-2-13 11:27
ps122 发表于 2020-2-13 11:18
new IvParameterSpec(a)
static byte[] a = { 85, 60, 12, 116, 99, -67, -83, 19, -118, -73, -24, -8,  ...

大神,请问怎么转换成16字节?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 18:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表