List of usage examples for java.security SecureRandom getInstance
public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException
From source file:org.wso2.carbon.identity.oidc.session.DefaultOIDCSessionStateManager.java
private static String generateSaltValue() throws NoSuchAlgorithmException { byte[] bytes = new byte[16]; SecureRandom secureRandom = SecureRandom.getInstance(RANDOM_ALG_SHA1); secureRandom.nextBytes(bytes);/* w w w .j a va 2s.c o m*/ return Base64.encodeBase64URLSafeString(bytes); }
From source file:org.toffi.domainmodel.encryptor.impl.AESEncryptorImpl.java
/** * Initializes encryptor with current encryption key. * * @param password// w w w.j ava 2 s .co m */ public AESEncryptorImpl(String password) { try { // key = new SecretKeySpec(DigestUtils.sha256(password), "AES"); key = new SecretKeySpec(DigestUtils.sha256(password), 0, 16, Constants.AES); // initialize secure random random = SecureRandom.getInstance(Constants.SHA1PRNG); // initialize ciphers encCipher = Cipher.getInstance(Constants.AES_MODE); decCipher = Cipher.getInstance(Constants.AES_MODE); ivLen = encCipher.getBlockSize(); } catch (Exception e) { throw new EncryptorException("Error while initializing AESEncryptorImpl.", e); } }
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.ProjectFile.java
public String generateReference() { MessageDigest md = null;// ww w . j ava 2s. c o m SecureRandom prng = null; try { md = MessageDigest.getInstance("SHA1"); prng = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { } String randomNum = new Integer(prng.nextInt()).toString(); String ref = new String(Hex.encodeHex(md.digest(randomNum.getBytes()))); return ref.toUpperCase().substring(0, 24); }
From source file:SuperPeer.java
/** * SuperPeer Constructor. It takes the number of bits in the key. *///from w w w.j a v a2 s. c o m SuperPeer(int _mbits) throws RemoteException, NoSuchAlgorithmException { lock = false; lg = new Logger("SuperPeer"); mbits = _mbits; peertable = new TreeSet<PeerInfo>(new PeerInfoComparator()); prng = SecureRandom.getInstance("SHA1PRNG"); hasher = new SHA1Hasher(mbits); lg.log(Level.FINER, "SuperPeer started."); }
From source file:org.linagora.linshare.core.utils.HashUtils.java
/** * generate salt (32 bits/4 octets)//w w w.jav a 2 s. c o m * @return */ public static byte[] getSalt() { // Get 32 random bits byte[] mybytes; try { // Create a secure random number generator SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); // Create secure number generator with seed int seedByteCount = 10; byte[] seed = sr.generateSeed(seedByteCount); sr = SecureRandom.getInstance("SHA1PRNG"); sr.setSeed(seed); mybytes = new byte[32 / 8]; sr.nextBytes(mybytes); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } return mybytes; }
From source file:eu.uqasar.service.AuthenticationService.java
/** * * @return @throws NoSuchAlgorithmException *//*w w w. j a v a 2 s . c o m*/ public static byte[] generateSalt() throws NoSuchAlgorithmException { // VERY important to use SecureRandom instead of just Random SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); // Generate a 8 byte (64 bit) salt as recommended by RSA PKCS5 byte[] salt = new byte[8]; random.nextBytes(salt); return salt; }
From source file:com.hypersocket.auth.PasswordEncryptionService.java
public byte[] generateSalt() throws NoSuchAlgorithmException { // VERY important to use SecureRandom instead of just Random SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); // Generate a 8 byte (64 bit) salt as recommended by RSA PKCS5 byte[] salt = new byte[8]; random.nextBytes(salt);//w ww . j a va 2 s .co m return salt; }
From source file:org.taverna.server.master.worker.PasswordIssuer.java
public PasswordIssuer(String algorithm) throws NoSuchAlgorithmException { r = SecureRandom.getInstance(algorithm); log.info("constructing passwords with " + r.getAlgorithm()); setLength(8);/*from w w w .j a va 2 s. com*/ }
From source file:uk.ac.horizon.ubihelper.protocol.ProtocolManager.java
public ProtocolManager() { random = new Random(System.currentTimeMillis()); try {/*from www. j a v a 2s.co m*/ srandom = SecureRandom.getInstance("SHA1PRNG"); } catch (Exception e) { logger.warning("Could not get SecureRandom: " + e); } try { messageDigest = MessageDigest.getInstance("MD5"); } catch (Exception e) { logger.warning("Could not get MessageDigest: " + e); } }
From source file:org.underworldlabs.util.DesEncrypter.java
public static String generateKey(int length) { try {//from w ww .j av a 2s. c om StringBuffer key = new StringBuffer(length); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); byte[] intbytes = new byte[4]; for (int i = 0; i < length; i++) { random.nextBytes(intbytes); key.append(pwdChars[Math.abs(getIntFromByte(intbytes) % pwdChars.length)]); } return key.toString(); } catch (NoSuchAlgorithmException e) { return null; } }