Code example for SecureRandom

Methods: setSeed

0
     *  
     */ 
    public static Map<String, Object> initRsaKey() throws Exception {
        KeyPairGenerator keyPairGen = KeyPairGenerator
                .getInstance(RSA_ALGORITHM);
        SecureRandom random = new SecureRandom();//加密随机数生成器 (RNG)
        random.setSeed(GUIDGenerator.instance().generate().getBytes());  //  设置随机种子
        keyPairGen.initialize(1024,random);
        KeyPair keyPair = keyPairGen.generateKeyPair();
        // 公钥 
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        // 私钥 
        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
        Map<String, Object> keyMap = new HashMap<String, Object>(2);
        keyMap.put(RSA_PUBLIC_KEY, publicKey);
        keyMap.put(RSA_PRIVATE_KEY, privateKey);
        return keyMap;
    } 
     
     
Stop searching for code, let great code find you!  Add Codota to your java IDE