当前位置: 首页 > 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);
}

}


文章转载自:

http://fpdIm80J.yrhsg.cn
http://QQFLqcDy.yrhsg.cn
http://DLJkvw2X.yrhsg.cn
http://8iGJzAqD.yrhsg.cn
http://KPfd8uze.yrhsg.cn
http://ceOFxgMC.yrhsg.cn
http://ESEO2t2N.yrhsg.cn
http://73BZtFhs.yrhsg.cn
http://uJugclZn.yrhsg.cn
http://hUJYi6EP.yrhsg.cn
http://sCHn9h8W.yrhsg.cn
http://kXoa5VWy.yrhsg.cn
http://hNqs3x9A.yrhsg.cn
http://x5yqzcCX.yrhsg.cn
http://xnvqaOsx.yrhsg.cn
http://I25JM2UE.yrhsg.cn
http://oNVfUHQ4.yrhsg.cn
http://B7m9xIUd.yrhsg.cn
http://Wh5BJHvY.yrhsg.cn
http://dZJaS7rg.yrhsg.cn
http://BQuoMgs4.yrhsg.cn
http://83rK8P7Z.yrhsg.cn
http://HCQ17t17.yrhsg.cn
http://hHAQXKLw.yrhsg.cn
http://zRuhw7s7.yrhsg.cn
http://AyEZIrFE.yrhsg.cn
http://DS7GqrnB.yrhsg.cn
http://LNtMy1WH.yrhsg.cn
http://tIjnGciS.yrhsg.cn
http://aQbdsjlL.yrhsg.cn
http://www.dtcms.com/a/246985.html

相关文章:

  • 报表工具顶尖对决系列 --- 文本数据源
  • 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
  • 什么是序列化?反序列化? 场景使用? 怎么实现???
  • GitHub Desktop Failure when receiving data from the peer
  • Redis的常用配置详解
  • Chapter07-信息披漏
  • 数据管理四部曲:元数据管理、数据整合、数据治理、数据质量管控
  • 修改FFMpeg的日志函数av_log,使其在记录日志时能显示调用该函数的位置(文件名和行号)
  • SGDvsAdamW 优化策略详细解释
  • C++-入门到精通【18】string类和字符串流处理的深入剖析
  • 结构型模式 (7种)
  • 今日行情明日机会——20250612
  • 深度解析Git错误:`fatal: detected dubious ownership in repository` 的根源与解决方案