0
点赞
收藏
分享

微信扫一扫

Java,PHP RSA加密解密,分段加解密及RSA签名

Villagers 2022-03-23 阅读 99
javaphp
  1. 对接第三方支付系统接口,为这通信的安全性,通常有MD5签名,RSA签名为主,今天主要讲解RSA加解密及签名。
  2. RSA密钥长度有1024和2048位的,由于RSA加密的特殊性,文本内容过长不进行分段加密的话会出来加密失败
  3. 1024加密长度为:117,解密长度为:128; 2048加密长度为:245,解密长度为:256,这个地方特别需要注意,根据密钥长度修改不同的参数值

JAVA RSA加解密工具类源码:

package com.pay.utils;

import java.io.ByteArrayOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.Cipher;

public class RSAEncrypt {
/**
* 字节数据转字符串专用集合
*/

private static final
举报

相关推荐

0 条评论