List of usage examples for java.security NoSuchAlgorithmException getLocalizedMessage
public String getLocalizedMessage()
From source file:pl.com.radio.services.Utils.java
/** * @param digest is define using hash functions (SHA-256) * @param data the input to be updated before the digest is completed * @return the array of bytes for the resulting hash value *//*from w w w . j a v a 2 s. co m*/ public static String digest(String digest, byte[] data) { try { java.security.MessageDigest md = java.security.MessageDigest.getInstance(digest); return Hex.encodeHexString(md.digest(data)); } catch (java.security.NoSuchAlgorithmException e) { System.out.println(e.getLocalizedMessage()); } return null; }
From source file:tw.com.ksmt.cloud.libs.Utils.java
public static String getMD5(String input) { try {//from w ww . ja v a 2 s.com MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String md5 = number.toString(16); while (md5.length() < 32) { md5 = "0" + md5; } return md5; } catch (NoSuchAlgorithmException e) { Log.e("MD5", e.getLocalizedMessage()); return null; } }
From source file:org.apache.hadoop.mapreduce.security.TestTokenCache.java
private static void createTokenFileJson() throws IOException { Map<String, String> map = new HashMap<String, String>(); try {/*from w w w. ja va 2 s.c o m*/ KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1"); for (int i = 0; i < NUM_OF_KEYS; i++) { SecretKeySpec key = (SecretKeySpec) kg.generateKey(); byte[] enc_key = key.getEncoded(); map.put("alias" + i, new String(Base64.encodeBase64(enc_key))); } } catch (NoSuchAlgorithmException e) { throw new IOException(e); } try { File p = new File(tokenFileName.getParent().toString()); p.mkdirs(); // convert to JSON and save to the file mapper.writeValue(new File(tokenFileName.toString()), map); } catch (Exception e) { System.out.println("failed with :" + e.getLocalizedMessage()); } }
From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java
public static String login(String email, String pass) throws IOException { // Server URL setup String _url = getBaseUri().appendPath("Login").build().toString(); // Establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.POST); addRequestHeader(conn, true);/* w ww. j a v a 2s.c o m*/ // prepare POST payload ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); try { // hash the password pass = Utilities.computeHash(pass); } catch (NoSuchAlgorithmException e) { Log.e(TAG, e.getLocalizedMessage()); } // Build JSON Object jgen.writeStartObject(); jgen.writeStringField(Keys.User.EMAIL, email); jgen.writeStringField("password", pass); jgen.writeEndObject(); jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); ps.close(); // Send payload int responseCode = sendPostPayload(conn, payload); String response = getServerResponse(conn); /* * result should get valid={"userID":"##"} * invalid={"errorID":"3","errorMessage":"invalid username or password"} */ String result = ""; if (!response.isEmpty()) { JsonNode tree = MAPPER.readTree(response); if (!tree.has(Keys.User.ID)) { logError(TAG, tree); result = "invalid username or password"; } else result = tree.get(Keys.User.ID).asText(); } conn.disconnect(); return result; }
From source file:com.qut.middleware.esoemanager.util.PolicyIDGenerator.java
public PolicyIDGenerator() { this.lock = new ReentrantLock(); try {/* ww w . j a va 2s . c o m*/ /* Attempt to get the specified RNG instance */ this.random = SecureRandom.getInstance(this.RNG); } catch (NoSuchAlgorithmException nsae) { this.logger.error(Messages.getString("IdentifierGeneratorImpl.13")); //$NON-NLS-1$ this.logger.debug(nsae.getLocalizedMessage(), nsae); this.random = new SecureRandom(); } this.random.setSeed(System.currentTimeMillis()); }
From source file:org.jspresso.framework.util.resources.server.ResourceManager.java
/** * Registers a resource./*from w ww . j av a 2 s.c om*/ * * @param resource * the resource to be registered. * @return the generated identifier under which the resource has been * registered. */ public String register(IResourceBase resource) { try { String id = createId(); resources.put(id, resource); return id; } catch (NoSuchAlgorithmException nsae) { throw new IllegalStateException("Could not generate random id: " + nsae.getLocalizedMessage()); } }
From source file:com.qut.middleware.saml2.identifier.impl.IdentifierGeneratorImpl.java
public IdentifierGeneratorImpl(IdentifierCache cache) { if (cache == null) { throw new IllegalArgumentException("identifier cache cannot be null."); //$NON-NLS-1$ }//from w ww .j av a 2s . com this.cache = cache; this.lock = new ReentrantLock(); try { /* Attempt to get the specified RNG instance */ this.random = SecureRandom.getInstance(this.RNG); } catch (NoSuchAlgorithmException nsae) { this.logger.error(Messages.getString("IdentifierGeneratorImpl.13")); //$NON-NLS-1$ this.logger.debug(nsae.getLocalizedMessage(), nsae); this.random = new SecureRandom(); } this.random.setSeed(System.currentTimeMillis()); }
From source file:com.textuality.keybase.lib.prover.Prover.java
public boolean checkRawMessageBytes(InputStream in) { try {//from ww w. j a v a 2 s . c o m MessageDigest digester = MessageDigest.getInstance("SHA-256"); byte[] buffer = new byte[8192]; int byteCount; while ((byteCount = in.read(buffer)) > 0) { digester.update(buffer, 0, byteCount); } String digest = Base64.encodeToString(digester.digest(), Base64.URL_SAFE); if (!digest.startsWith(mShortenedMessageHash)) { mLog.add("Proof post doesnt contain correct encoded message."); return false; } return true; } catch (NoSuchAlgorithmException e) { mLog.add("SHA-256 not available"); } catch (IOException e) { mLog.add("Error checking raw message: " + e.getLocalizedMessage()); } return false; }
From source file:com.smartmarmot.dbforbix.config.Config.java
public static String calculateMD5Sum(String inStr) { MessageDigest hasher = null;/*from w w w . ja va 2s . co m*/ try { hasher = java.security.MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { LOG.error("Wrong hashing algorithm name provided while getting instance of MessageDigest: " + e.getLocalizedMessage()); } return (new HexBinaryAdapter()).marshal(hasher.digest(inStr.getBytes())); }
From source file:org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.java
/** * Constructor SignatureRSA//ww w. j av a 2 s. co m * * @throws XMLSignatureException */ public SignatureBaseRSA() throws XMLSignatureException { String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI()); if (log.isDebugEnabled()) { log.debug("Created SignatureRSA using " + algorithmID); } String provider = JCEMapper.getProviderId(); try { if (provider == null) { this.signatureAlgorithm = Signature.getInstance(algorithmID); } else { this.signatureAlgorithm = Signature.getInstance(algorithmID, provider); } } catch (java.security.NoSuchAlgorithmException ex) { Object[] exArgs = { algorithmID, ex.getLocalizedMessage() }; throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); } catch (NoSuchProviderException ex) { Object[] exArgs = { algorithmID, ex.getLocalizedMessage() }; throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); } }