当前位置: 首页 > news >正文

分块解密,,,

import java.security.PrivateKey;
import java.security.Security;
import javax.crypto.Cipher;
import java.util.Base64;

public class RsaDecryptUtil {

public static String decrypt(String encryptedData, PrivateKey privateKey) throws Exception {// 添加BouncyCastle提供者支持Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());// 初始化解密器Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");cipher.init(Cipher.DECRYPT_MODE, privateKey);// 分块解密byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData);ByteArrayOutputStream out = new ByteArrayOutputStream();int offset = 0;int maxDecryptBlock = 245;while (offset < encryptedBytes.length) {int length = Math.min(encryptedBytes.length - offset, maxDecryptBlock);byte[] decryptedBlock = cipher.doFinal(encryptedBytes, offset, length);out.write(decryptedBlock);offset += length;}// 返回解密结果return new String(out.toByteArray(), "UTF-8");
}// 加载私钥示例(假设私钥已加载为字符串)
public static PrivateKey loadPrivateKey(String privateKeyStr) throws Exception {byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyStr);PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);KeyFactory keyFactory = KeyFactory.getInstance("RSA");return keyFactory.generatePrivate(keySpec);
}public static void main(String[] args) throws Exception {// 假设的私钥字符串String privateKeyStr = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQD...";PrivateKey privateKey = loadPrivateKey(privateKeyStr);// 待解密的密文String encryptedData = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...";// 解密String decryptedData = decrypt(encryptedData, privateKey);System.out.println("解密结果:" + decryptedData);
}

}

相关文章:

  • 报表工具顶尖对决系列 --- 文本数据源
  • C++内存管理与编译链接
  • 数据结构 散列表 学习 2025年6月12日15:30:48
  • SpringMVC与Struts2对比教学
  • Jetpack LiveData 深度解析
  • 武汉科技大学人工智能与演化计算实验室许志伟课题组参加IEEE CEC 2025
  • AI集成运维管理平台的架构与核心构成解析
  • Python训练打卡Day48
  • 开源PSS解析器
  • Linux部署bmc TrueSight 监控agent步骤
  • 股指期货入门基础知识
  • 智能体应用开发课程体系规划说明
  • vue组件对外属性类型错误接收问题
  • 打卡day52
  • Appium + Python 测试全流程
  • FFmpeg是什么?
  • 106.给AI回答添加点赞收藏功能
  • AI技术专题:电商AI专题
  • PERST#、Hot Reset、Link Disable
  • 什么是序列化?反序列化? 场景使用? 怎么实现???
  • sae部署wordpress/最新seo视频教程
  • 南宁网站建设电话/线下课程seo
  • 网站开发项目报价单/优化大师免费安装下载
  • 公司网站外包建设没有源代码/东莞网站到首页排名
  • 镇江网站建设找思创/沧州seo包年优化软件排名
  • 黑龙江网站建设/chrome手机版