List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:com.appzone.sim.services.handlers.PhoneRegistrationServiceHandler.java
public String getMD5(String input) { try {// w w w. j a va 2 s .c o m MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String hashtext = number.toString(16); // Now we need to zero pad it if you actually want the full 32 // chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:com.artivisi.iso8583.Processor.java
public Message stringToMessage(String stream) { LOGGER.debug("[STRING2MESSAGE] : [{}]", stream); if (stream == null || stream.trim().length() < MTI_LENGTH + BITMAP_LENGTH) { LOGGER.error("[STRING2MESSAGE] : Invalid Message [{}]", stream); throw new IllegalArgumentException("Invalid Message : [" + stream + "]"); }//from w ww . j a v a2 s. c om int currentPosition = 0; Message m = new Message(); m.setMti(stream.substring(0, MTI_LENGTH)); currentPosition += MTI_LENGTH; String primaryBitmapStream = stream.substring(currentPosition, currentPosition + BITMAP_LENGTH); m.setPrimaryBitmapStream(primaryBitmapStream); currentPosition += BITMAP_LENGTH; LOGGER.debug("[STRING2MESSAGE] : Primary Bitmap Hex : [{}]", primaryBitmapStream); String primaryBitmapBinary = new BigInteger(primaryBitmapStream, HEXADECIMAL).toString(BINARY); LOGGER.debug("[STRING2MESSAGE] : Primary Bitmap Bin : [{}]", primaryBitmapBinary); if (m.isDataElementPresent(1)) { String secondaryBitmapStream = stream.substring(currentPosition, currentPosition + BITMAP_LENGTH); LOGGER.debug("[STRING2MESSAGE] : Secondary Bitmap Hex : [{}]", secondaryBitmapStream); m.setSecondaryBitmapStream(secondaryBitmapStream); currentPosition += BITMAP_LENGTH; } // mulai dari 2, karena bitmap tidak diparsing for (int i = 2; i <= NUMBER_OF_DATA_ELEMENT; i++) { if (!m.isDataElementPresent(i)) { continue; } DataElement de = mapper.getDataElement().get(i); if (de == null) { LOGGER.error("[STRING2MESSAGE] - [DATA ELEMENT {}] : Not configured", i); throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] not configured"); } if (DataElementLength.FIXED.equals(de.getLengthType())) { if (de.getLength() == null || de.getLength() < 1) { LOGGER.error( "[STRING2MESSAGE] - [DATA ELEMENT {}] : Length not configured for fixed length element", i); throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] length not configured for fixed length element"); } String data = stream.substring(currentPosition, currentPosition + de.getLength()); m.getDataElementContent().put(i, data); LOGGER.debug("[STRING2MESSAGE] - [DATA ELEMENT {}] : [{}]", i, data); currentPosition += de.getLength(); continue; } if (DataElementLength.VARIABLE.equals(de.getLengthType())) { if (de.getLengthPrefix() == null || de.getLengthPrefix() < 1) { LOGGER.error( "[STRING2MESSAGE] - [DATA ELEMENT {}] : Length prefix not configured for variable length element", i); throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] length prefix not configured for variable length element"); } String strLength = stream.substring(currentPosition, currentPosition + de.getLengthPrefix()); currentPosition += de.getLengthPrefix(); try { Integer length = Integer.parseInt(strLength); String data = stream.substring(currentPosition, currentPosition + length); m.getDataElementContent().put(i, data); LOGGER.debug("[STRING2MESSAGE] - [DATA ELEMENT {}] : [{}]", i, data); currentPosition += length; continue; } catch (NumberFormatException err) { LOGGER.error("[STRING2MESSAGE] - [DATA ELEMENT {}] : Length prefix [{}] cannot be parsed", new Object[] { i, strLength }); throw err; } } LOGGER.error("[STRING2MESSAGE] - [DATA ELEMENT {}] : Length type [{}] not fixed nor variable", new Object[] { i, de.getLengthType() }); throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] length type [" + de.getLengthType() + "] not fixed nor variable"); } return m; }
From source file:com.comcast.cmb.common.util.AuthUtil.java
public static boolean verifyPassword(String password, String hashedPassword) throws Exception { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] hashedBytes = new BigInteger(hashedPassword, 16).toByteArray(); String salt = new String(hashedBytes, 0, 4); String toBeHashed = salt + password; byte[] hashed = digest.digest(toBeHashed.getBytes("UTF-8")); for (int i = 0; i < hashed.length; i++) { if (hashed[i] != hashedBytes[i + 4]) { return false; }/*from www .j a v a 2 s . c om*/ } return true; }
From source file:fi.vm.kapa.identification.service.PhaseIdService.java
/** * Creates new standard length token ID that is used to calculate * the phase ID./* w ww . ja va 2s . c o m*/ * * @return New token ID as alphanumeric string */ public String nextTokenId() { String token = new BigInteger(130, new SecureRandom()).toString(32); while (token.length() != TID_LENGTH) { token = new BigInteger(130, new SecureRandom()).toString(32); } return token; }
From source file:com._64bitlabs.util.Encryptors.java
/** * Generates random salt string//from ww w .j ava2 s . c o m * @return random salt string */ public static String nextSalt() { SecureRandom random = new SecureRandom(); return new BigInteger(130, random).toString(32); }
From source file:br.ufrn.fonoweb.service.ArquivoService.java
public String getEncodedFileName(String originalFile, byte[] contents) { MessageDigest md = null;// w w w . j a va2s .c o m String result = null; try { md = MessageDigest.getInstance("SHA-256"); md.update(contents); result = new BigInteger(1, md.digest()).toString(16); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ArquivoService.class.getName()).log(Level.SEVERE, null, ex); return null; } result = result.concat(".").concat(FilenameUtils.getExtension(originalFile)); return result; }
From source file:org.marietjedroid.connect.MarietjeMessenger.java
/** * Generates a new token/*from ww w . j a v a 2 s .c o m*/ * * @return a new token */ protected static String generateToken() { SecureRandom random = new SecureRandom(); while (true) { String attempt = new BigInteger(130, random).toString(); attempt = new String(org.apache.commons.codec.binary.Base64.encodeBase64(attempt.getBytes())) .substring(0, 7); return attempt; } }
From source file:com.khipu.lib.java.KhipuService.java
private static String byteArrayToString(byte[] data) { BigInteger bigInteger = new BigInteger(1, data); String hash = bigInteger.toString(16); while (hash.length() < 64) { hash = "0" + hash; }/*from w w w . ja v a 2s . c om*/ return hash; }
From source file:com.exalttech.trex.packets.TrexEthernetPacket.java
/** * * @param builder/*from www . j a v a2 s. c o m*/ */ public void buildPacket(AbstractPacket.AbstractBuilder builder) { if (builder == null) { this.type = EtherType.getInstance((short) 0xFFFF); } ethernetBuilder = new EthernetPacket.Builder(); ethernetBuilder.dstAddr(dstAddr).srcAddr(srcAddr).type(type).payloadBuilder(builder); byte[] pad; if (builder == null || addPad) { if (payload != null) { String payloadString = payload.getPayloadType().getPadPayloadString(payload.getPayloadPattern(), 100000); pad = new BigInteger(payloadString, 16).toByteArray(); } else { pad = new byte[0]; } ethernetBuilder.paddingAtBuild(false).pad(pad); this.packet = ethernetBuilder.build(); fixPacketLength(); } else { ethernetBuilder.paddingAtBuild(true); this.packet = ethernetBuilder.build(); } }
From source file:com.vmware.identity.openidconnect.client.TestUtils.java
static X509Certificate generateCertificate(KeyPair keyPair, String dn, String subjectAltName) throws Exception { ContentSigner sigGen = new JcaContentSignerBuilder("SHA1withRSA").build(keyPair.getPrivate()); Date startDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); Date endDate = new Date(System.currentTimeMillis() + 365 * 24 * 60 * 60 * 1000); X509v3CertificateBuilder v3CertGen = new JcaX509v3CertificateBuilder(new X500Name("CN=" + dn), new BigInteger(64, new SecureRandom()), startDate, endDate, new X500Name("CN=" + dn), keyPair.getPublic());/*from w w w . j a v a 2s . c om*/ if (subjectAltName != null) { v3CertGen .addExtension(Extension.subjectAlternativeName, true, new GeneralNames(new GeneralName(GeneralName.otherName, new DERSequence(new ASN1Encodable[] { new DERObjectIdentifier("1.3.6.1.4.1.311.20.2.3"), new DERTaggedObject(true, 0, new DERUTF8String(subjectAltName)) })))); } X509CertificateHolder certHolder = v3CertGen.build(sigGen); X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate(certHolder); return x509Certificate; }