I need to generate RSA key pair in java.I tried the following,
<%@page import="java.security.Key"%>
<%@page import="java.security.KeyPair"%>
<%@page import="java.security.KeyPairGenerator"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
out.println("PrivateKey:" + privateKey);
out.println("PublicKey:" +publicKey);
%>
</body>
</html>
when the page is running in netbeans(this page only) an error is occuring.,error: package
sun.org.mozilla.javascript.internal.regexp does not exist
when the entire project is running I got the output..., but the generated public key is too long...,like this
PrivateKey:sun.security.rsa.RSAPrivateCrtKeyImpl@b8a7c
PublicKey:Sun RSA public key, 2048 bits modulus:
16357206704297604671856121853158662273841275717667103178663872982510600516942159
92471768797559279747649637039251872720857162699034207744835023844213276461437235
62716346732316118850882643586149442248236190221255104694771208469870082732902270
59176928873062588804197238673756206442086637249330898308938378378066971049120606
00637770477260198883852885925396692544417880794817246467903698369172064896388091
16103893445868520394887338681032080760488563541369139420725965115593026544388053
89245256261473050095495300460611881341368409054850562520674680342153131165041561
752280363820799023393672676767368529573441046320095568301
public exponent: 65537
I want to insert this public key and private key into database..,so it should be small.., please help me......,