Example usage for java.security SecureRandom SecureRandom

List of usage examples for java.security SecureRandom SecureRandom

Introduction

In this page you can find the example usage for java.security SecureRandom SecureRandom.

Prototype

public SecureRandom() 

Source Link

Document

Constructs a secure random number generator (RNG) implementing the default random number algorithm.

Usage

From source file:MainClass.java

public static KeyPair generateRSAKeyPair() throws Exception {
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
    kpGen.initialize(1024, new SecureRandom());
    return kpGen.generateKeyPair();
}

From source file:com.intel.mountwilson.trustagent.commands.SetAssetTag.java

public SetAssetTag(TADataContext context) {
    this.context = context;
    this.random = new SecureRandom();
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static void enableSSLUnsecureTrustStore() {
    try {//ww  w  .j  a  va  2 s.  c  om
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
    } catch (NoSuchAlgorithmException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("NO TLS ALGORITHM EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    } catch (KeyManagementException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("KEY MANAGEMENT CREATION EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    }
}

From source file:de.hybris.platform.b2b.punchout.services.impl.AsymmetricManager.java

/**
 * Generates a random salt.//from www.j a  v a2s .c o  m
 * 
 * @return The salt.
 */
public static String getSalt() {
    final byte[] salt = new byte[SALT_LEN];
    final SecureRandom rnd = new SecureRandom();
    rnd.nextBytes(salt);
    return Hex.encodeHexString(salt);
}

From source file:net.link.util.test.pkix.PkiTestUtils.java

public static KeyPair generateKeyPair(String algorithm)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
    SecureRandom random = new SecureRandom();
    if ("RSA".equals(keyPairGenerator.getAlgorithm()))
        keyPairGenerator.initialize(new RSAKeyGenParameterSpec(RSA_KEYSIZE, RSAKeyGenParameterSpec.F4), random);
    else if (keyPairGenerator instanceof DSAKeyPairGenerator) {
        DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator;
        dsaKeyPairGenerator.initialize(DSA_MODLEN, false, random);
    }/*www  .  ja v a  2 s.c om*/
    return keyPairGenerator.generateKeyPair();
}

From source file:com.hobba.hobaserver.services.security.ChallengeUtil.java

public String getChallenge(String kid, long expirationTime) {
    HobaKeys hk = new HobaKeys();
    HobaKeysFacadeREST hkfrest = new HobaKeysFacadeREST();
    HobaChallengesFacadeREST hcfrest = new HobaChallengesFacadeREST();
    hk = hkfrest.findHKIDbyKID(kid);/* ww  w  .  java  2  s  .c  o  m*/

    SecureRandom random = new SecureRandom();
    String rand = new BigInteger(130, random).toString(32);

    HobaChallenges hc = new HobaChallenges();

    hc.setIdKeys(hk);
    hc.setChalenge(rand);
    if (expirationTime > 0) {
        Date date = new Date(new Date().getTime() + (expirationTime * 100));
        hc.setExpiration(date);
    }
    hc.setExpiration(null);
    hc.setIsValid(Boolean.TRUE);
    hcfrest.create(hc);

    return new String(Base64.encodeBase64(rand.getBytes()));
}

From source file:net.mc_cubed.msrp.MsrpUtil.java

/**
 * Generate a RFC 4975 Section 14.1 compliant SessionId for use in an MSRP
 * URI/*from  w  w w  .ja  v a2 s  .co  m*/
 * @return
 */
public static String generateMsrpUriSessionId() {
    SecureRandom secure = new SecureRandom();
    byte[] bytes = new byte[MSRP_URI_SESSION_LENGTH];
    secure.nextBytes(bytes);
    return Base64.encodeBase64String(bytes);
}

From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.AbstractSslContext.java

protected static SSLContext getCertificateSSLContext() throws GeneralSecurityException {
    SSLContext sslContext = getSSLContext();
    JSONObject sslConf = null;/*w w  w.  j  av a2s  .  c  o  m*/
    try {
        sslConf = readSSLConfToJson();
    } catch (Exception e) {
        LOG.error("readSSLConfToJson error", e);
    }
    sslContext.init(createKeyManager(sslConf), createTrustManager(sslConf), new SecureRandom());
    return sslContext;
}

From source file:com.medsphere.ovid.common.uuid.KeyGenerator.java

public KeyGenerator() {
    try {/*from   w ww.j  a va2 s  .  com*/
        InetAddress inet = InetAddress.getLocalHost();
        byte[] bytes = inet.getAddress();
        String inetAddressInHex = new String(Hex.encodeHex(bytes));
        String hashCodeForThis = new String(Hex.encodeHex(intToByteArray(System.identityHashCode(this))));
        middle = inetAddressInHex + hashCodeForThis;
        seeder = new SecureRandom();
        seeder.nextInt();

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        seeder = new SecureRandom();
        seeder.nextInt();
        middle = new Integer(this.hashCode()).toString();
    }

}

From source file:bit.changepurse.wdk.bip.MnemonicService.java

public MnemonicService(Bip39Dict aDict) {
    dict = aDict;
    rng = new SecureRandom();
}