List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:org.mitre.oauth2.service.impl.DefaultClientUserDetailsService.java
@Override public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException { try {//from www . j av a 2s .co m ClientDetailsEntity client = clientDetailsService.loadClientByClientId(clientId); if (client != null) { String password = Strings.nullToEmpty(client.getClientSecret()); if (config.isHeartMode() || // if we're running HEART mode turn off all client secrets (client.getTokenEndpointAuthMethod() != null && (client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY) || client.getTokenEndpointAuthMethod().equals(AuthMethod.SECRET_JWT)))) { // Issue a random password each time to prevent password auth from being used (or skipped) // for private key or shared key clients, see #715 password = new BigInteger(512, new SecureRandom()).toString(16); } boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; Collection<GrantedAuthority> authorities = new HashSet<>(client.getAuthorities()); authorities.add(ROLE_CLIENT); return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); } else { throw new UsernameNotFoundException("Client not found: " + clientId); } } catch (InvalidClientException e) { throw new UsernameNotFoundException("Client not found: " + clientId); } }
From source file:com.sfalma.trace.Sfalma.java
public static String MD5(String data) throws Exception { MessageDigest m = MessageDigest.getInstance("MD5"); m.update(data.getBytes(), 0, data.length()); return new BigInteger(1, m.digest()).toString(16); }
From source file:com.artivisi.iso8583.Message.java
public void setSecondaryBitmapStream(String bitmap) { this.secondaryBitmap = new BigInteger(bitmap, 16); }
From source file:com.github.sebhoss.identifier.service.SuppliedIdentifiers.java
private static String convertFromBaseToBase(final String value, final int from, final int to) { return new BigInteger(value, from).toString(to); }
From source file:com.siberhus.geopoint.restclient.GeoPointRestClient.java
/** * // w ww.j av a2s .c o m * @param ipAddr * @param format * @return */ public IpInfo query(String ipAddr, Format format) { Assert.notNull("apiKey", apiKey); Assert.notNull("secret", secret); Assert.notNull("ipAddr", ipAddr); Assert.notNull("format", format); MessageDigest digest = null; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { // should not happen throw new RuntimeException(e); } String formatStr = format == Format.XML ? "xml" : "json"; long timeInSeconds = (long) (System.currentTimeMillis() / 1000); String input = apiKey + secret + timeInSeconds; digest.update(input.getBytes()); String signature = String.format("%032x", new BigInteger(1, digest.digest())); String url = serviceUrl + ipAddr + "?apikey=" + apiKey + "&sig=" + signature + "&format=" + formatStr; log.debug("Calling Quova ip2loc service from URL: {}", url); DefaultHttpClient httpclient = new DefaultHttpClient(); // Create an HTTP GET request HttpGet httpget = new HttpGet(url); // Execute the request httpget.getRequestLine(); HttpResponse response = null; try { response = httpclient.execute(httpget); } catch (IOException e) { throw new HttpRequestException(e); } HttpEntity entity = response.getEntity(); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { throw new HttpRequestException(status.getReasonPhrase()); } // Print the response log.debug("Response status: {}", status); StringBuilder responseText = new StringBuilder(); if (entity != null) { try { InputStream inputStream = entity.getContent(); // Process the response BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bufferedReader.readLine()) != null) { responseText.append(line); } bufferedReader.close(); } catch (IOException e) { throw new HttpRequestException(e); } } // shut down the connection manager to ensure // immediate deallocation of all system resources. httpclient.getConnectionManager().shutdown(); IpInfo ipInfo = null; if (format == Format.XML) { JAXBContext context; try { context = JAXBContext.newInstance(IpInfo.class); Unmarshaller um = context.createUnmarshaller(); ipInfo = (IpInfo) um.unmarshal(new StringReader(responseText.toString())); } catch (JAXBException e) { throw new ResultParseException(e); } } else { ObjectMapper mapper = new ObjectMapper(); try { ipInfo = mapper.readValue(new StringReader(responseText.toString()), IpInfoWrapper.class) .getIpInfo(); } catch (IOException e) { throw new ResultParseException(e); } } return ipInfo; }
From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.helper.CertificateHandler.java
public void createFakedCertificate() throws CertificateHandlerException { try {//from ww w . j av a 2s. co m Logging.getInstance().log(getClass(), "Faking the found certificate", Logging.DEBUG); KeyPairGenerator kpg = KeyPairGenerator.getInstance(originalPublicKey.getAlgorithm()); kpg.initialize(((RSAPublicKey) certificate.getPublicKey()).getModulus().bitLength()); fakedKeyPair = kpg.generateKeyPair(); X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); v3CertGen.setSubjectDN(certificate.getSubjectX500Principal()); v3CertGen.setIssuerDN(certificate.getIssuerX500Principal()); v3CertGen.setNotAfter(certificate.getNotAfter()); v3CertGen.setNotBefore(certificate.getNotBefore()); v3CertGen.setSerialNumber(new BigInteger(64, new Random())); v3CertGen.setSignatureAlgorithm(certificate.getSigAlgName()); v3CertGen.setPublicKey(fakedKeyPair.getPublic()); fakedCertificate = v3CertGen.generate(fakedKeyPair.getPrivate()); } catch (CertificateEncodingException | SecurityException | SignatureException | InvalidKeyException | NoSuchAlgorithmException e) { throw new CertificateHandlerException(e); } }
From source file:com.github.neio.filesystem.paths.TestFilePath.java
@Test public void testHashCode() throws IOException { FileUtils.writeStringToFile(new File(testDir, "testFile"), "Hello World"); Assert.assertEquals(new BigInteger("a4d55a8d778e5022fab701977c5d840bbc486d0", 16).hashCode(), new FilePath("./testTempDir/testFile").hashCode()); }