List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:org.openhab.io.rest.internal.resources.ContextResource.java
private String md5(String s) { try {/*from w w w. j a va2s . c o m*/ MessageDigest m = MessageDigest.getInstance("MD5"); m.update(s.getBytes(), 0, s.length()); BigInteger i = new BigInteger(1, m.digest()); return String.format("%1$032x", i); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:it.uniroma2.sag.kelp.wordspace.Wordspace.java
public Wordspace() { words = new TLongObjectHashMap<char[]>(); vectors = new TLongObjectHashMap<Vector>(); try {//from ww w .ja v a2s . co m wordEncoder = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.zimbra.cs.octosync.PatchInputStream.java
private InputStream nextInputStream() throws IOException, ServiceException { if (!patchReader.hasMoreRecordInfos()) { return null; }// w w w .j a va2s .c o m PatchReader.RecordInfo ri = patchReader.getNextRecordInfo(); InputStream nextStream = null; if (ri.type == PatchReader.RecordType.DATA) { log.debug("Patch data, length: " + ri.length); nextStream = patchReader.popData(); } else if (ri.type == PatchReader.RecordType.REF) { PatchRef patchRef = patchReader.popRef(); log.debug("Patch reference " + patchRef); if (patchRef.length > MAX_REF_LENGTH) { throw new InvalidPatchReferenceException( "referenced data too large: " + patchRef.length + " > " + MAX_REF_LENGTH); } if (manifest != null) { int[] actualRef = blobAccess.getActualReference(patchRef.fileId, patchRef.fileVersion); manifest.addReference(actualRef[0], actualRef[1], patchRef.length); } try { InputStream blobIs = blobAccess.getBlobInputStream(patchRef.fileId, patchRef.fileVersion); blobIs.skip(patchRef.offset); byte[] chunkBuf = new byte[patchRef.length]; DataInputStream dis = new DataInputStream(blobIs); dis.readFully(chunkBuf); dis.close(); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(chunkBuf); byte[] calcHash = md.digest(); if (!Arrays.equals(patchRef.hashKey, calcHash)) { throw new InvalidPatchReferenceException("refrenced data hash mismatch, actual hash: " + new String(Hex.encodeHex(calcHash)) + "; " + patchRef); } nextStream = new ByteArrayInputStream(chunkBuf); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); assert false : "SHA-256 must be supported"; } } else { assert false : "Invalid record type: " + ri.type; } assert nextStream != null : "Stream returned here must be non-null"; return nextStream; }
From source file:org.opendatakit.security.spring.UserServiceImpl.java
@Override public boolean isSuperUsernamePasswordSet(CallingContext cc) throws ODKDatastoreException { if (superUserUsername == null) { return true; }/*from w w w . j a v a 2 s .c o m*/ if (superUserUsernameRecord == null) { // retrieve the underlying record superUserUsernameRecord = RegisteredUsersTable.getUserByUsername(superUserUsername, this, cc.getDatastore()); } if (superUserUsernameRecord != null) { RealmSecurityInfo r = new RealmSecurityInfo(); r.setRealmString(this.getCurrentRealm().getRealmString()); CredentialsInfo credential; try { credential = CredentialsInfoBuilder.build(superUserUsername, r, "aggregate"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new IllegalStateException("unrecognized algorithm"); } return !credential.getDigestAuthHash().equals(superUserUsernameRecord.getDigestAuthPassword()); } return true; }
From source file:com.ericsun.duom.DuoMApplication.java
private SSLSocketFactory createSocketFactory() { SSLSocketFactory sf = null;/*from w w w. j av a 2 s. c o m*/ try { MySSLSocketFactory sslFy = new MySSLSocketFactory(null); sf = sslFy.sslContext.getSocketFactory(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } return sf; }
From source file:com.dreamlinx.automation.DINRelay.java
/** * This method returns a message digest of the given string using the * MD5 message digest algorithm. If the MD5 algorithm is not available in * the caller's environment, then the original message is returned. * * @param value Arbitrary length message to digest. * @return 32 character MD5 message digest of given message. *//*from w w w . ja v a 2 s .c om*/ public String toMD5(String value) { byte axMsg[] = value.getBytes(); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte axMD5[] = md5.digest(axMsg); StringBuffer sbMD5 = new StringBuffer(axMD5.length * 2); for (int iByteIdx = 0; iByteIdx < axMD5.length; iByteIdx++) { String hexByte = "0" + Integer.toHexString(new Byte(axMD5[iByteIdx]).intValue()); sbMD5.append(hexByte.substring(hexByte.length() - 2)); } return sbMD5.toString().toLowerCase(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return value; } }
From source file:angel.zhuoxiu.library.pusher.Pusher.java
private String authenticate(String channelName) { if (!isConnected()) { Log.e(LOG_TAG, "pusher not connected, can't create auth string"); return null; }/*from w ww. j av a2 s . c o m*/ try { String stringToSign = mSocketId + ":" + channelName; SecretKey key = new SecretKeySpec(mPusherSecret.getBytes(), PUSHER_AUTH_ALGORITHM); Mac mac = Mac.getInstance(PUSHER_AUTH_ALGORITHM); mac.init(key); byte[] signature = mac.doFinal(stringToSign.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < signature.length; ++i) { sb.append(Integer.toHexString((signature[i] >> 4) & 0xf)); sb.append(Integer.toHexString(signature[i] & 0xf)); } String authInfo = mPusherKey + ":" + sb.toString(); Log.d(LOG_TAG, "Auth Info " + authInfo); return authInfo; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }
From source file:com.dtolabs.rundeck.core.resources.URLResourceModelSource.java
private String hashURL(final String url) { try {//from w w w . jav a 2 s . c o m MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); digest.update(url.getBytes(Charset.forName("UTF-8"))); return new String(Hex.encodeHex(digest.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return Integer.toString(url.hashCode()); }
From source file:org.jmangos.auth.wow.controller.AccountController.java
public boolean checkSessionKey(final AccountInfo account, final byte[] R1, final byte[] R2) { MessageDigest sha = null;//from ww w . j a va 2 s . com try { sha = MessageDigest.getInstance("SHA-1"); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); return false; } final AccountEntity accountEntity = this.accountService.readAccountByUserName(account.getName()); if (accountEntity != null) { final String sessionKey = accountEntity.getSessionKey(); sha.update(account.getName().getBytes(Charset.forName("UTF-8"))); sha.update(R1); sha.update(account.get_reconnectProof().asByteArray(16)); sha.update(convertSessionKey(sessionKey)); } else { return false; } if (Arrays.equals(sha.digest(), R2)) { return true; } else { return false; } }
From source file:org.jmangos.realm.network.packet.auth.client.CMD_AUTH_LOGON_CHALLENGE.java
@Override protected void readImpl() throws BufferUnderflowException, RuntimeException { readC();//from ww w. j av a 2 s.c o m if (readC() == WoWAuthResponse.WOW_SUCCESS.getMessageId()) { final SecureRandom random = new SecureRandom(); MessageDigest sha = null; try { sha = MessageDigest.getInstance("SHA-1"); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); return; } final BigInteger k = new BigInteger("3"); final byte[] Bb = readB(32); final BigInteger g = new BigInteger(readB(readC())); final byte[] Nb = readB(readC()); final byte[] saltb = readB(32); /* byte[] unk3 = */readB(16); readC(); ArrayUtils.reverse(Bb); final BigInteger B = new BigInteger(1, Bb); ArrayUtils.reverse(Bb); ArrayUtils.reverse(Nb); final BigInteger N = new BigInteger(1, Nb); ArrayUtils.reverse(Nb); final BigInteger a = new BigInteger(1, random.generateSeed(19)); final byte[] passhash = sha.digest(this.config.AUTH_LOGIN.toUpperCase().concat(":") .concat(this.config.AUTH_PASSWORD.toUpperCase()).getBytes(Charset.forName("UTF-8"))); sha.update(saltb); sha.update(passhash); final byte[] xhash = sha.digest(); ArrayUtils.reverse(xhash); final BigInteger x = new BigInteger(1, xhash); logger.debug("x:" + x.toString(16).toUpperCase()); final BigInteger v = g.modPow(x, N); logger.debug("v:" + v.toString(16).toUpperCase()); final BigInteger A = g.modPow(a, N); logger.debug("A:" + A.toString(16).toUpperCase()); logger.debug("B:" + B.toString(16).toUpperCase()); this.ahash = A.toByteArray(); ArrayUtils.reverse(this.ahash); sha.update(this.ahash); sha.update(Bb); final byte[] hashu = sha.digest(); ArrayUtils.reverse(hashu); final BigInteger u = new BigInteger(1, hashu); logger.debug("u:" + u.toString(16).toUpperCase()); final BigInteger S = (B.subtract(k.multiply(g.modPow(x, N)))).modPow(a.add(u.multiply(x)), N); final byte[] full_S = S.toByteArray(); ArrayUtils.reverse(full_S); logger.debug("t:" + StringUtils.toHexString(full_S)); final byte[] s1_hash = new byte[16]; final byte[] s2_hash = new byte[16]; for (int i = 0; i < 16; i++) { s1_hash[i] = full_S[i * 2]; s2_hash[i] = full_S[(i * 2) + 1]; } final byte[] t1 = sha.digest(s1_hash); final byte[] t2 = sha.digest(s2_hash); final byte[] vK = new byte[40]; for (int i = 0; i < 20; i++) { vK[i * 2] = t1[i]; vK[(i * 2) + 1] = t2[i]; } byte[] hash = new byte[20]; logger.debug("N:" + N.toString(16).toUpperCase()); hash = sha.digest(Nb); logger.debug("hash:" + new BigInteger(1, hash).toString(16).toUpperCase()); byte[] gH = new byte[20]; sha.update(g.toByteArray()); gH = sha.digest(); for (int i = 0; i < 20; ++i) { hash[i] ^= gH[i]; } byte[] t4 = new byte[20]; t4 = sha.digest(this.config.AUTH_LOGIN.toUpperCase().getBytes(Charset.forName("UTF-8"))); sha.update(hash); logger.debug("hash:" + StringUtils.toHexString(hash)); sha.update(t4); logger.debug("t4:" + StringUtils.toHexString(t4)); sha.update(saltb); logger.debug("saltb:" + StringUtils.toHexString(saltb)); sha.update(this.ahash); logger.debug("ahash:" + StringUtils.toHexString(this.ahash)); sha.update(Bb); logger.debug("Bb:" + StringUtils.toHexString(Bb)); sha.update(vK); logger.debug("vK:" + StringUtils.toHexString(vK)); this.m1 = sha.digest(); sha.update(this.ahash); sha.update(this.m1); sha.update(vK); logger.debug("m1 value" + StringUtils.toHexString(this.m1)); @SuppressWarnings("unused") final byte[] m2 = sha.digest(); final ChannelPipeline pipeline = getClient().getChannel().getPipeline(); ((RealmToAuthChannelHandler) pipeline.getLast()).setSeed(vK); } else { getChannel().getPipeline().remove("handler"); getChannel().getPipeline().remove("eventlog"); getChannel().getPipeline().remove("executor"); getChannel().close(); getChannel().getFactory().releaseExternalResources(); } }