當我創建一個RSA密鑰對我應該做公鑰VS RSAPublicKeySpec
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kp = kpg.genKeyPair();
PublicKey publicKey = kp.getPublic();
PrivateKey privateKey = kp.getPrivate();
save("public.key",publicKey.getEncoded())
save("private.key",privateKey.getEncoded())
OR
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(),RSAPrivateKeySpec.class);
saveToFile("public.key", pub.getModulus(),pub.getPublicExponent());
saveToFile("private.key", priv.getModulus(),priv.getPrivateExponent());
哪個更好,有什麼區別?
嗨,我有一個小小的懷疑。我有模數和指數。我需要創建PublicKey。你可以讓我知道如何創建「公鑰」給出'模數'和'指數'。 – Andhravaala 2010-07-12 10:38:56