以下是自动生成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();
}
}
}