List of usage examples for java.math BigInteger toString
public String toString(int radix)
From source file:org.sipfoundry.sipxbridge.SipXauthIdentity.java
static private String encodeIdentity(String identity, String callId, String fromTag, long timestamp) { // calculate timestamp Long seconds = timestamp / 1000; String stamp = Long.toHexString(seconds).toUpperCase(); String strSignature = stamp + SignatureFieldSeparator; // signature-hash=MD5(<timestamp><secret><from-tag><call-id><identity>) try {//from ww w . j a v a 2 s .c om MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(stamp.getBytes()); digest.update(sSignatureSecretDecoded); digest.update(fromTag.getBytes()); digest.update(callId.getBytes()); digest.update(identity.getBytes()); // create md5 hash of token byte md5hash[] = digest.digest(); BigInteger number = new BigInteger(1, md5hash); strSignature += number.toString(16); } catch (Exception ex) { logger.error("Failed to generate signature", ex); } String encodedUrl = "<sip:" + identity + ";signature=" + strSignature + ">"; return encodedUrl; }
From source file:org.wso2.carbon.apimgt.gateway.utils.APIMgtGoogleAnalyticsUtils.java
/** * Generates a 32 character length random number for cacheBusterId * * @return cacheBusterId/*from w w w. j ava 2s . co m*/ * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException */ public static String getCacheBusterId() throws NoSuchAlgorithmException, UnsupportedEncodingException { String message = getRandomNumber() + UUID.randomUUID().toString(); MessageDigest m = MessageDigest.getInstance("MD5"); m.update(message.getBytes("UTF-8"), 0, message.length()); byte[] sum = m.digest(); BigInteger messageAsNumber = new BigInteger(1, sum); String md5String = messageAsNumber.toString(16); // Pad to make sure id is 32 characters long. while (md5String.length() < 32) { md5String = "0" + md5String; } return "0x" + md5String.substring(0, 16); }
From source file:util.Support.java
public static String encryptMD5(String pw) { try {//from w ww. j a v a2 s.com MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(pw.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String hashText = number.toString(16); while (hashText.length() < 32) { hashText = "0" + hashText; } return hashText; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(); } }
From source file:com.vmware.identity.idm.CommonUtil.java
public static String Computesha256Hash(File secretFile) throws IOException, NoSuchAlgorithmException { FileInputStream fs = null;/* www.j ava 2 s. c om*/ try { fs = new FileInputStream(secretFile); MessageDigest md = MessageDigest.getInstance("SHA-256"); DigestInputStream dis = new DigestInputStream(fs, md); while ((dis.read()) != -1) ; BigInteger bi = new BigInteger(md.digest()); return bi.toString(64); } finally { if (fs != null) { fs.close(); } } }
From source file:org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil.java
/** * @param dataPathId datapath id in big interger value * @return string of size 16, padded with '0' *//*from ww w . ja v a2 s . c o m*/ public static String bigIntegerToPaddedHex(final BigInteger dataPathId) { return StringUtils.leftPad(dataPathId.toString(16), 16, "0"); }
From source file:edu.hm.muse.controller.Logincontroller.java
public static String calculateSHA256(InputStream is) { String output;//from w w w .ja va2 s . c om int read; byte[] buffer = new byte[8192]; try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] hash = digest.digest(); BigInteger bigInt = new BigInteger(1, hash); output = bigInt.toString(16); } catch (Exception e) { e.printStackTrace(System.err); return "0"; } return output; }
From source file:net.sf.keystore_explorer.utilities.io.HexUtil.java
/** * Get hex string for the supplied big integer: "0x<hex string>" where hex * string is outputted in groups of exactly four characters sub-divided by * spaces.//from w w w . j a v a2s .c o m * * @param bigInt * Big integer * @return Hex string */ public static String getHexString(BigInteger bigInt) { // Convert number to hex string String hex = bigInt.toString(16).toUpperCase(); // Get number padding bytes int padding = (4 - (hex.length() % 4)); // Insert any required padding to get groups of exactly 4 characters if ((padding > 0) && (padding < 4)) { StringBuffer sb = new StringBuffer(hex); for (int i = 0; i < padding; i++) { sb.insert(0, '0'); } hex = sb.toString(); } // Output with leading "0x" and spaces to form groups StringBuffer strBuff = new StringBuffer(); strBuff.append("0x"); for (int i = 0; i < hex.length(); i++) { strBuff.append(hex.charAt(i)); if ((((i + 1) % 4) == 0) && ((i + 1) != hex.length())) { strBuff.append(' '); } } return strBuff.toString(); }
From source file:com.sixsq.slipstream.cookie.CryptoUtils.java
/** * Sign the given data and return a String representation of the signature. * The argument may not be null.//from ww w. ja v a 2 s .com * * @param data * information to sign * * @return String representation of the signature. */ public static String sign(String data) { try { Signature signature = Signature.getInstance(signatureAlgorithm); signature.initSign(privateKey); signature.update(data.getBytes()); BigInteger biSignature = new BigInteger(signature.sign()); return biSignature.toString(radix); } catch (NoSuchAlgorithmException nsae) { return null; } catch (InvalidKeyException ike) { return null; } catch (SignatureException se) { return null; } }
From source file:org.apache.accumulo.server.master.tableOps.Utils.java
static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException { String tableId = null;/* www . j av a 2 s .c om*/ try { IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance(); final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES; byte[] nid = zoo.mutate(ntp, "0".getBytes(), ZooUtil.PUBLIC, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { BigInteger nextId = new BigInteger(new String(currentValue), Character.MAX_RADIX); nextId = nextId.add(BigInteger.ONE); return nextId.toString(Character.MAX_RADIX).getBytes(); } }); return new String(nid); } catch (Exception e1) { Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1); throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage()); } }
From source file:Pusher.java
/** * Converts a byte array to a string representation * @param data// w w w . j ava 2s . c o m * @return */ private static String byteArrayToString(byte[] data) { BigInteger bigInteger = new BigInteger(1, data); String hash = bigInteger.toString(16); // Zero pad it while (hash.length() < 32) { hash = "0" + hash; } return hash; }