以下是自动生成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 2020-07-06 21:21  Sandm-1  阅读(123)  评论(0编辑  收藏  举报