List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:org.runway.utils.TextUtils.java
/** * Generates MD5 for the text passed/* w w w. j a v a 2 s .c om*/ * @param text * @return */ public static String genMD5(String text) { MessageDigest m; try { m = MessageDigest.getInstance("MD5"); m.update(text.getBytes(), 0, text.length()); return new BigInteger(1, m.digest()).toString(16); } catch (NoSuchAlgorithmException e) {// return same text if there was // an error e.printStackTrace(); return text; } }
From source file:services.SecurityService.java
public String hashPassword(String UserPassword) throws NoSuchAlgorithmException { String password = UserPassword + this.RANDOM_SALT; MessageDigest m = MessageDigest.getInstance("MD5"); m.update(password.getBytes(), 0, password.length()); return new BigInteger(1, m.digest()).toString(16); }
From source file:org.cloudfoundry.community.servicebroker.postgresql.service.Role.java
public String bindRoleToDatabase(String dbInstanceId) throws SQLException { Utils.checkValidUUID(dbInstanceId);//from w w w .java 2 s . c o m SecureRandom random = new SecureRandom(); String passwd = new BigInteger(130, random).toString(32); PostgreSQLDatabase.executeUpdate("ALTER ROLE \"" + dbInstanceId + "\" LOGIN password '" + passwd + "'"); return passwd; }
From source file:au.gov.dto.dibp.appointments.security.csrf.CookieBasedCsrfTokenRepository.java
@Override public CsrfToken generateToken(HttpServletRequest request) { String tokenValue = new BigInteger(130, secureRandom).toString(32); // http://stackoverflow.com/a/41156 return new DefaultCsrfToken(CSRF_HEADER_NAME, CSRF_COOKIE_AND_PARAMETER_NAME, tokenValue); }
From source file:io.mapzone.controller.um.repository.AuthToken.java
private AuthToken() { // http://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string data = new BigInteger(130, random.get()); }
From source file:net.peterkuterna.appengine.apps.devoxxsched.util.Md5Calculator.java
public String calculateMd5() { final byte[] response = getResponse(requestUri); if (response != null) { try {//ww w.j av a 2 s . c o m MessageDigest mdEnc = MessageDigest.getInstance("MD5"); mdEnc.update(response); return new BigInteger(1, mdEnc.digest()).toString(16); } catch (NoSuchAlgorithmException e) { } } return null; }
From source file:ezbake.warehaus.WarehausUtils.java
public static Text getKey(String uri) { try {/*from w w w . j a va2 s .c o m*/ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.update(uri.getBytes()); byte[] hash = messageDigest.digest(); BigInteger bigInt = new BigInteger(1, hash); String hashtext = bigInt.toString(16); return new Text(hashtext + ":" + uri); } catch (NoSuchAlgorithmException e) { // We hopefully should never end up here logger.error("NoSuchAlgorithmException thrown while attempting " + "to hash key.", e); throw new RuntimeException(e); } }
From source file:com.github.tell.arithmetic.integer.gmp.MPZBenchmarking.java
@SuppressWarnings("UnusedAssignment") private static StopWatch mulWithBigInteger(final int length) { final BigInteger x1 = new BigInteger(length, secureRandom); final BigInteger x2 = new BigInteger(length, secureRandom); @SuppressWarnings("unused") BigInteger x3 = BigInteger.valueOf(0); final StopWatch timer = new StopWatch(); timer.start();/*w w w .j a v a 2 s . c om*/ for (int j = 0; j < numOfLoop; j++) { x3 = x1.multiply(x2); } timer.stop(); printout(timer, length, "BigInteger"); return timer; }
From source file:com.github.horrorho.inflatabledonkey.cloudkitty.CloudKitty.java
public static CloudKitty backupd(CKInit ckInit, String cloudKitToken) { String container = "com.apple.backup.ios"; String bundle = "com.apple.backupd"; String cloudKitUserId = ckInit.cloudKitUserId(); String baseUrl = ckInit.production().url(); String deviceID = UUID.randomUUID().toString(); String deviceHardwareID = new BigInteger(256, ThreadLocalRandom.current()).toString(16) .toUpperCase(Locale.US); RequestOperationFactory factory = new RequestOperationFactory(cloudKitUserId, container, bundle, deviceHardwareID, deviceID); InputStreamResponseHandler<List<CloudKit.ResponseOperation>> responseHandler = new InputStreamResponseHandler<>( new RawProtoDecoderLogger(null)); return new CloudKitty(factory, container, bundle, cloudKitUserId, cloudKitToken, baseUrl, responseHandler); }
From source file:com.baran.file.FileOperator.java
public static String uniqueNameGenerator(String inputFile) { // randomization SecureRandom random = new SecureRandom(); BigInteger bi = new BigInteger(130, random); String uniqueEncFile = String.valueOf((BigInteger) bi); // commons-io-2.4.jar String fileNameWithOutExt = FilenameUtils.removeExtension(inputFile); String randomFileName = System.getProperty("user.dir") + "\\" + fileNameWithOutExt + "_" + uniqueEncFile + ".enc"; return randomFileName; }