javarsa代码 java代码例子讲解( 十 )


String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnmBlx+lc/pviri9dUQ0WjXRweGEHmYKqSRj0UsAXpYLxKB7tv3zbNW5oHyYSPJYa/6Px8vBBQfyPww8i3AnFOGwi7caZIvHnQviiUdlr8mH51ZlhHv96to0lSkX/NfOvKvQndzDH60DzLGOMdE0NBrTn/5zEjGwJbVdlvCfOiHwIDAQAB";
RSAUtils rsaUtil = new RSAUtils();
String encryptByPublicKey = rsaUtil.encryptByPublicKey("你好!", PUBLIC_KEY);
System.out.println(encryptByPublicKey);
String decryptByPrivateKey = rsaUtil.decryptByPrivateKey(encryptByPublicKey, PRIVATE_KEY);
System.out.println(decryptByPrivateKey);
String encryptByPrivateKey = rsaUtil.encryptByPrivateKey("你好!", PRIVATE_KEY);
System.out.println(encryptByPrivateKey);
String decryptByPublicKey = rsaUtil.decryptByPublicKey(encryptByPrivateKey, PUBLIC_KEY);
System.out.println(decryptByPublicKey);
String sign = rsaUtil.sign("1234", PRIVATE_KEY);
System.out.println("sign:" + sign);
System.out.println(rsaUtil.verify("1234", PUBLIC_KEY, sign));
}
}
java RSA算法实现256位密钥怎么做参考下面代码:
try {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA",
new org.bouncycastle.jce.provider.BouncyCastleProvider());
final int KEY_SIZE = 128;// 没什么好说的了,这个值关系到块加密的大小 , 可以更改,但是不要太大,否则效率会低
keyPairGen.initialize(KEY_SIZE, new SecureRandom());
KeyPair keyPair = keyPairGen.generateKeyPair();
return keyPair;
} catch (Exception e) {
throw new Exception(e.getMessage());
}
javarsa代码的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于java代码例子讲解、javarsa代码的信息别忘了在本站进行查找喔 。

推荐阅读