ONExiaobaijs 2021-06-27 00:55 采纳率: 0%
浏览 154

java aes 找iv IvParameterSpec(new

package com.ads.web.app.network;

import android.util.Base64;
import java.security.MessageDigest;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AESCrypt {
    public static final String SEED_16_CHARACTER = "DaCheAPPAesKey";
    private final Cipher cipher;
    private static AESCrypt instance;
    private final SecretKeySpec key;
    private AlgorithmParameterSpec spec;

    static {
    }

    public AESCrypt() throws Exception {
        super();
        MessageDigest v0 = MessageDigest.getInstance("SHA-256");
        v0.update("DaCheAPPAesKey".getBytes("UTF-8"));
        byte[] v1 = new byte[32];
        System.arraycopy(v0.digest(), 0, v1, 0, v1.length);
        this.cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
        this.key = new SecretKeySpec(v1, "AES");
        this.spec = this.getIV();
    }

    public String decrypt(String arg5) throws Exception {
        this.cipher.init(2, this.key, this.spec);
        return new String(this.cipher.doFinal(Base64.decode(arg5, 0)), "UTF-8");
    }

    public String encrypt(String arg5) throws Exception {
        this.cipher.init(1, this.key, this.spec);
        return new String(Base64.encode(this.cipher.doFinal(arg5.getBytes("UTF-8")), 0), "UTF-8");
    }

    public AlgorithmParameterSpec getIV() {
        return new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
    }
                                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    public static AESCrypt getInstance() {
        try {
            if(AESCrypt.instance == null) {
                AESCrypt.instance = new AESCrypt();
            }

            return AESCrypt.instance;
        }
        catch(Exception ) {
            return null;
        }
    }
}

真么让iv输出出来呀

  • 写回答

1条回答 默认 最新

  • 关注

    AESCrypt aes = new AESCrypt();

    String str= aes.decrypt(参数);

     

    评论

报告相同问题?

悬赏问题

  • ¥100 对接美团闪购医药接口相关问题
  • ¥15 嵌入式软件电子烟开发
  • ¥15 职场 Excel 查重问题
  • ¥20 multisim方波发生电路产生的波形异常,学校没讲模电就留了实验qwq
  • ¥15 求怎么用idea2021.3.2创建web项目并配置tomcat
  • ¥100 or-tools的相关问题
  • ¥15 有可能用平板通过拓展坞来烧录程序吗(keil5的那种)
  • ¥15 状态图的并发态问题咨询
  • ¥15 PFC3D,plot
  • ¥15 VAE模型编程报错无法解决