以下是自动生成moduls,公钥,私钥的相关代码:(仅供参考)
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
public class Encrypt {
public static void main(String[] args) {
try {
KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
KeyPair pair = rsa.generateKeyPair();
System.out.println("mod:"+((RSAPublicKey)pair.getPublic()).getModulus().toString());
System.out.println("公钥:"+((RSAPublicKey)pair.getPublic()).getPublicExponent().toString());
System.out.println("私钥:"+((RSAPrivateKey)pair.getPrivate()).getPrivateExponent().toString());
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}



版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2015-09-22 21:05  Sandm-1  阅读(64)  评论(0编辑  收藏  举报