[Java] java实现RSA加密和解密 →→→→→进入此内容的聊天室

来自 , 2020-04-08, 写在 Java, 查看 164 次.
URL http://www.code666.cn/view/d714d2c5
  1. public static void main(String[] args) throws Exception {
  2.                 // TODO Auto-generated method stub
  3.                 HashMap<String, Object> map = RSAUtils.getKeys();
  4.                 //生成公钥和私钥
  5.                 RSAPublicKey publicKey = (RSAPublicKey) map.get("public");
  6.                 RSAPrivateKey privateKey = (RSAPrivateKey) map.get("private");
  7.                
  8.                 //模
  9.                 String modulus = publicKey.getModulus().toString();
  10.                 //公钥指数
  11.                 String public_exponent = publicKey.getPublicExponent().toString();
  12.                 //私钥指数
  13.                 String private_exponent = privateKey.getPrivateExponent().toString();
  14.                 //明文
  15.                 String ming = "123456789";
  16.                 //使用模和指数生成公钥和私钥
  17.                 RSAPublicKey pubKey = RSAUtils.getPublicKey(modulus, public_exponent);
  18.                 RSAPrivateKey priKey = RSAUtils.getPrivateKey(modulus, private_exponent);
  19.                 //加密后的密文
  20.                 String mi = RSAUtils.encryptByPublicKey(ming, pubKey);
  21.                 System.err.println(mi);
  22.                 //解密后的明文
  23.                 ming = RSAUtils.decryptByPrivateKey(mi, priKey);
  24.                 System.err.println(ming);
  25.         }
  26.  
  27.  
  28. //java/6652

回复 " java实现RSA加密和解密"

这儿你可以回复上面这条便签

captcha