|
@ -4,6 +4,7 @@ import java.security.*;
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
import java.security.interfaces.RSAPublicKey;
|
|
|
import java.security.spec.X509EncodedKeySpec;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
|
@ -37,6 +38,19 @@ public class RSAUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static HashMap<String, Object> generateKeys() throws NoSuchAlgorithmException {
|
|
|
HashMap<String, Object> map = new HashMap();
|
|
|
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", new BouncyCastleProvider());
|
|
|
keyPairGen.initialize(1024, new SecureRandom());
|
|
|
KeyPair keyPair = keyPairGen.generateKeyPair();
|
|
|
RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();
|
|
|
RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();
|
|
|
map.put("public", publicKey);
|
|
|
map.put("private", privateKey);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成public key
|
|
|
* @return
|