use of java.security.SecureRandom in project sonarqube by SonarSource.
the class JwtCsrfVerifier method generateState.
public String generateState(HttpServletRequest request, HttpServletResponse response, int timeoutInSeconds) {
// Create a state token to prevent request forgery.
// Store it in the cookie for later validation.
String state = new BigInteger(130, new SecureRandom()).toString(32);
response.addCookie(newCookieBuilder(request).setName(CSRF_STATE_COOKIE).setValue(state).setHttpOnly(false).setExpiry(timeoutInSeconds).build());
return state;
}
use of java.security.SecureRandom in project sonarqube by SonarSource.
the class OAuthCsrfVerifier method generateState.
public String generateState(HttpServletRequest request, HttpServletResponse response) {
// Create a state token to prevent request forgery.
// Store it in the session for later validation.
String state = new BigInteger(130, new SecureRandom()).toString(32);
response.addCookie(newCookieBuilder(request).setName(CSRF_STATE_COOKIE).setValue(sha256Hex(state)).setHttpOnly(true).setExpiry(-1).build());
return state;
}
use of java.security.SecureRandom in project sonarqube by SonarSource.
the class AesCipher method generateRandomSecretKey.
String generateRandomSecretKey() {
try {
KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_KEY);
keyGen.init(KEY_SIZE_IN_BITS, new SecureRandom());
SecretKey secretKey = keyGen.generateKey();
return Base64.encodeBase64String(secretKey.getEncoded());
} catch (Exception e) {
throw new IllegalStateException("Fail to generate secret key", e);
}
}
use of java.security.SecureRandom in project RxCache by VictorAlbertos.
the class BuiltInEncryptor method generateSecretKey.
private SecretKeySpec generateSecretKey(String key) throws Exception {
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes("UTF-8"));
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(KEY_LENGTH, secureRandom);
SecretKey secretKey = keyGenerator.generateKey();
return new SecretKeySpec(secretKey.getEncoded(), "AES");
}
use of java.security.SecureRandom in project OpenAttestation by OpenAttestation.
the class X509Builder method randomSerial.
public X509Builder randomSerial() {
try {
BigInteger sn = new BigInteger(64, new SecureRandom());
certificateSerialNumber = new CertificateSerialNumber(sn);
info.set(X509CertInfo.SERIAL_NUMBER, certificateSerialNumber);
} catch (Exception e) {
fault(e, "randomSerial");
}
return this;
}
Aggregations