List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:Main.java
public static String encodeBase58(byte[] input) { if (input == null) { return null; }/*from w ww . j av a 2 s . com*/ StringBuilder str = new StringBuilder((input.length * 350) / 256 + 1); BigInteger bn = new BigInteger(1, input); long rem; while (true) { BigInteger[] divideAndRemainder = bn.divideAndRemainder(BASE58_CHUNK_MOD); bn = divideAndRemainder[0]; rem = divideAndRemainder[1].longValue(); if (bn.compareTo(BigInteger.ZERO) == 0) { break; } for (int i = 0; i < BASE58_CHUNK_DIGITS; i++) { str.append(BASE58[(int) (rem % 58)]); rem /= 58; } } while (rem != 0) { str.append(BASE58[(int) (rem % 58)]); rem /= 58; } str.reverse(); int nLeadingZeros = 0; while (nLeadingZeros < input.length && input[nLeadingZeros] == 0) { str.insert(0, BASE58[0]); nLeadingZeros++; } return str.toString(); }
From source file:io.mapzone.controller.um.repository.AuthToken.java
private AuthToken(String token) { data = new BigInteger(token, 32); }
From source file:com.wirecard.ezlinkwebservices.util.TerminalUtil.java
public static synchronized String strXor(String s1, String s2) { System.out.println("strXor=" + s1 + " " + s2); BigInteger one = new BigInteger(s1, 16); BigInteger two = new BigInteger(s2, 16); BigInteger three = one.xor(two); String s3 = three.toString(16); System.out.println(s3);//from w w w. ja va 2 s . co m return s3; }
From source file:cherry.windows.charset.ListCreator.java
public void createList() throws IOException { Charset ms932 = Charset.forName("MS932"); Charset cp943 = Charset.forName("CP943"); Charset win31j = Charset.forName("Windows-31J"); System.out.println("WIN\tUNI\tMS932(1)\tMS932(2)\tCP943(1)\tCP943(2)\tWin31J(1)\tWin31J(2)\tCOMMENT"); List<Entry> list = tableParser.parse("CP932.TXT"); for (Entry entry : list) { System.out.print(entry.getWinCode()); System.out.print("\t"); System.out.print(entry.getUniCode()); System.out.print("\t"); BigInteger winCode = new BigInteger(entry.getWinCode(), 16); BigInteger bi932x1 = new BigInteger((new String(winCode.toByteArray(), ms932)).getBytes(ms932)); BigInteger bi932x2 = new BigInteger((new String(bi932x1.toByteArray(), ms932)).getBytes(ms932)); System.out.print(winCode.equals(bi932x1)); System.out.print("\t"); System.out.print(bi932x1.equals(bi932x2)); System.out.print("\t"); BigInteger bi943x1 = new BigInteger((new String(winCode.toByteArray(), cp943)).getBytes(cp943)); BigInteger bi943x2 = new BigInteger((new String(bi943x1.toByteArray(), cp943)).getBytes(cp943)); System.out.print(winCode.equals(bi943x1)); System.out.print("\t"); System.out.print(bi943x1.equals(bi943x2)); System.out.print("\t"); BigInteger bi31jx1 = new BigInteger((new String(winCode.toByteArray(), win31j)).getBytes(win31j)); BigInteger bi31jx2 = new BigInteger((new String(bi31jx1.toByteArray(), win31j)).getBytes(win31j)); System.out.print(winCode.equals(bi31jx1)); System.out.print("\t"); System.out.print(bi31jx1.equals(bi31jx2)); System.out.print("\t"); System.out.print(entry.getComment()); System.out.println();/*from w ww.ja va 2s .com*/ } }
From source file:au.gov.dto.springframework.security.web.csrf.CookieCsrfTokenRepository.java
@Override public CsrfToken generateToken(HttpServletRequest request) { String tokenValue = new BigInteger(130, secureRandom).toString(32); // http://stackoverflow.com/a/41156 return new DefaultCsrfToken(csrfHeaderName, csrfParameterName, tokenValue); }
From source file:org.gravidence.gravifon.util.BasicUtils.java
/** * Generates secure random token of specified length.<p> * Generated token contains following characters: <code>[0-9a-z]</code>. * /* www .ja va 2 s . co m*/ * @param numberOfBits token length in bits * @return secure random token */ public static String generateToken(int numberOfBits) { return new BigInteger(numberOfBits, SECURE_RANDOM).toString(Character.MAX_RADIX); }
From source file:Main.java
/** * Method for returning an md5 hash of a string. * /*from w w w . j a v a2 s.c om*/ * @param val * the string to hash. * @return A hex string representing the md5 hash of the input. */ private static String md5(String val) { String result = null; if ((val != null) && (val.length() > 0)) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(val.getBytes(), 0, val.length()); result = String.format("%032X", new BigInteger(1, md5.digest())); } catch (NoSuchAlgorithmException nsae) { result = val.substring(0, 32); } } return result; }
From source file:com.siphyc.utils.Utilities.java
public static String generateNonce() { return new BigInteger(130, random).toString(32); }
From source file:de.uniwue.info6.misc.StringTools.java
/** * * * @return */ public static String nextSessionId() { return new BigInteger(130, random).toString(32); }
From source file:com.offbynull.peernetic.common.identification.IdGenerator.java
/** * Constructs a {@link DefaultIdGenerator} object using a {@link Random} as its underlying source. * @param random random number generator (should be a {@link SecureRandom} instance in most cases) * @param limit maximum value the id generated can be * @throws NullPointerException if any arguments are {@code null} * @throws IllegalArgumentException if limit is 0 *///from ww w . jav a2 s . co m public IdGenerator(Random random, byte[] limit) { Validate.notNull(random); Validate.notNull(limit); Validate.isTrue(limit.length > 0 && !new BigInteger(1, limit).equals(BigInteger.ZERO)); this.random = random; this.limit = Arrays.copyOf(limit, limit.length); }