List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:eu.peppol.document.PayloadDigestCalculator.java
public static MessageDigestResult calcDigest(String algorithm, StandardBusinessDocumentHeader sbdh, InputStream inputStream) { MessageDigest messageDigest;/*from w ww . j a va 2s .com*/ try { messageDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Unknown digest algorithm " + OxalisConstant.DEFAULT_DIGEST_ALGORITHM + " " + e.getMessage(), e); } InputStream inputStreamToCalculateDigestFrom = null; ManifestItem manifestItem = SbdhFastParser.searchForAsicManifestItem(sbdh); if (manifestItem != null) { // creates an FilterInputStream, which will extract the ASiC in binary format. inputStreamToCalculateDigestFrom = new Base64InputStream(new AsicFilterInputStream(inputStream)); } else inputStreamToCalculateDigestFrom = inputStream; DigestInputStream digestInputStream = new DigestInputStream( new BufferedInputStream(inputStreamToCalculateDigestFrom), messageDigest); try { IOUtils.copy(digestInputStream, new NullOutputStream()); } catch (IOException e) { throw new IllegalStateException("Unable to calculate digest for payload"); } return new MessageDigestResult(messageDigest.digest(), messageDigest.getAlgorithm()); }
From source file:be.fedict.eid.idp.model.CryptoUtil.java
public static Mac getMac(byte[] hmacSecret) throws InvalidKeyException { SecretKey macKey = new SecretKeySpec(hmacSecret, "HmacSHA1"); Mac mac;//from w w w .ja v a2 s . c o m try { mac = Mac.getInstance(macKey.getAlgorithm()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("HMAC algo not available: " + e.getMessage()); } mac.init(macKey); return mac; }
From source file:com.proctorcam.proctorserv.HashedAuthenticator.java
public static HashMap<String, Object> applyReverseGuidAndSign(HashMap<String, Object> params, String customer_identifier, String shared_secret) { //Create random GUID SecureRandom secRandom = null; try {/*from w w w. j a v a 2 s . c om*/ secRandom = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException ex) { System.err.println(ex.getMessage()); } String guid = new Integer(secRandom.nextInt()).toString(); params.put("customer_id", customer_identifier); params.put("guid", guid); params.put("signature", ""); //Create query string using key-value pairs in params and //appending shared_secret StringBuilder query = new StringBuilder(); for (String key : params.keySet()) { if (key != "signature") { Object data = params.get(key); if (is_hashmap(data)) { HashMap<String, Object> map = (HashMap<String, Object>) data; String hashMapQuery = hashQuery(key, map); query.append(hashMapQuery); } else if (is_array(data)) { Object[] array = getArray(data); String arrayString = arrayQuery(key, array); query.append(arrayString); } else { query.append(key).append("=").append(data).append("&"); } } } //Deletes trailing & from query and append shared_secret query.deleteCharAt(query.length() - 1); query.append(shared_secret); String signature = buildSig(query); //Add signature to params params.put("signature", signature); //Reverse guid in params String reverseGUID = new StringBuilder(guid).reverse().toString(); params.put("guid", reverseGUID); return params; }
From source file:org.opendaylight.openflowplugin.applications.lldpspeaker.LLDPUtil.java
static byte[] buildLldpFrame(final NodeId nodeId, final NodeConnectorId nodeConnectorId, final MacAddress src, final Long outPortNo, final MacAddress destinationAddress) { // Create discovery pkt LLDP discoveryPkt = new LLDP(); // Create LLDP ChassisID TLV BigInteger dataPathId = dataPathIdFromNodeId(nodeId); byte[] cidValue = LLDPTLV.createChassisIDTLVValue(colonize(bigIntegerToPaddedHex(dataPathId))); LLDPTLV chassisIdTlv = new LLDPTLV(); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()).setLength((short) cidValue.length) .setValue(cidValue);//from ww w .j av a 2 s .c om discoveryPkt.setChassisId(chassisIdTlv); // Create LLDP PortID TL String hexString = Long.toHexString(outPortNo); byte[] pidValue = LLDPTLV.createPortIDTLVValue(hexString); LLDPTLV portIdTlv = new LLDPTLV(); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()).setLength((short) pidValue.length).setValue(pidValue); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()); discoveryPkt.setPortId(portIdTlv); // Create LLDP TTL TLV byte[] ttl = new byte[] { (byte) 0x13, (byte) 0x37 }; LLDPTLV ttlTlv = new LLDPTLV(); ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue()).setLength((short) ttl.length).setValue(ttl); discoveryPkt.setTtl(ttlTlv); // Create LLDP SystemName TLV byte[] snValue = LLDPTLV.createSystemNameTLVValue(nodeId.getValue()); LLDPTLV systemNameTlv = new LLDPTLV(); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()).setLength((short) snValue.length) .setValue(snValue); discoveryPkt.setSystemNameId(systemNameTlv); // Create LLDP Custom TLV byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnectorId.getValue()); LLDPTLV customTlv = new LLDPTLV(); customTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customValue.length) .setValue(customValue); discoveryPkt.addCustomTLV(customTlv); //Create LLDP CustomSec TLV byte[] pureValue = new byte[1]; try { pureValue = getValueForLLDPPacketIntegrityEnsuring(nodeConnectorId); byte[] customSecValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, pureValue); LLDPTLV customSecTlv = new LLDPTLV(); customSecTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customSecValue.length) .setValue(customSecValue); discoveryPkt.addCustomTLV(customSecTlv); } catch (NoSuchAlgorithmException e1) { LOG.info("LLDP extra authenticator creation failed: {}", e1.getMessage()); LOG.debug("Reason why LLDP extra authenticator creation failed: ", e1); } // Create ethernet pkt byte[] sourceMac = HexEncode.bytesFromHexString(src.getValue()); Ethernet ethPkt = new Ethernet(); ethPkt.setSourceMACAddress(sourceMac).setEtherType(EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt); if (destinationAddress == null) { ethPkt.setDestinationMACAddress(LLDP.LLDPMulticastMac); } else { ethPkt.setDestinationMACAddress(HexEncode.bytesFromHexString(destinationAddress.getValue())); } try { return ethPkt.serialize(); } catch (PacketException e) { LOG.warn("Error creating LLDP packet: {}", e.getMessage()); LOG.debug("Error creating LLDP packet.. ", e); } return null; }
From source file:org.projectforge.common.Crypt.java
private static byte[] getPassword(final String password) { try {// www . ja v a2 s. c o m final MessageDigest digester = MessageDigest.getInstance("MD5"); // 128 bit. 256 bit (SHA-256) doesn't work on Java versions without required security policy. digester.update(password.getBytes("UTF-8")); final byte[] key = digester.digest(); return key; } catch (final NoSuchAlgorithmException ex) { log.error("Exception encountered while trying to create a MD5 password: " + ex.getMessage(), ex); return null; } catch (final UnsupportedEncodingException ex) { log.error("Exception encountered while trying to get bytes in UTF-8: " + ex.getMessage(), ex); return null; } }
From source file:com.ikon.module.db.stuff.FsDataStore.java
/** * Persis document file/*from w w w . j a v a 2s . c o m*/ */ public static void persist(NodeDocumentVersion nDocVer, InputStream is) throws IOException { log.debug("persist({}, {})", nDocVer, is); if (FsDataStore.DATASTORE_BACKEND_FS.equals(Config.REPOSITORY_DATASTORE_BACKEND)) { File dsRaw = FsDataStore.save(nDocVer.getUuid(), is); if (Config.REPOSITORY_CONTENT_CHECKSUM) { try { String checkSum = SecureStore.md5Encode(dsRaw); nDocVer.setChecksum(checkSum); } catch (NoSuchAlgorithmException e) { log.warn(e.getMessage(), e); } } } else { byte[] raw = IOUtils.toByteArray(is); nDocVer.setContent(raw); if (Config.REPOSITORY_CONTENT_CHECKSUM) { try { String checkSum = SecureStore.md5Encode(raw); nDocVer.setChecksum(checkSum); } catch (NoSuchAlgorithmException e) { log.warn(e.getMessage(), e); } } } log.debug("persist: void"); }
From source file:com.mb.framework.util.SecurityUtil.java
/** * This method encrypts the password as per Md5 Algorithm. * // w w w .ja va2 s . c o m * @param String * @return String * */ public static String encryptMd5(String plaintext) throws Exception { MessageDigest md = null; try { md = MessageDigest.getInstance("SHA"); // step 2 } catch (NoSuchAlgorithmException e) { throw new Exception(e.getMessage()); } try { md.update(plaintext.getBytes("UTF-8")); // step 3 } catch (UnsupportedEncodingException e) { throw new Exception(e.getMessage()); } byte raw[] = md.digest(); // step 4 return new BASE64Encoder().encode(raw); // step 5 }
From source file:org.openhie.openempi.util.SessionGenerator.java
protected static synchronized MessageDigest getDigest() { if (SessionGenerator.digest == null) { try {/* w w w .ja va2 s . co m*/ digest = MessageDigest.getInstance(DEFAULT_ALGORITHM); } catch (NoSuchAlgorithmException e) { log.error("Unable to obtain a message digest algorithm: " + e, e); throw new RuntimeException("Unable to obtain a message digest algorithm: " + e.getMessage()); } } return digest; }
From source file:com.openkm.module.db.stuff.FsDataStore.java
/** * Verify checksum//from w ww. ja v a 2 s . co m */ public static void verifyChecksum(String docUuid, String verName, File fsRaw) throws RepositoryException, DatabaseException, IOException { log.debug("verifyChecksum({}, {}, {})", new Object[] { docUuid, verName, fsRaw }); Session session = null; try { String stChecksum = NodeDocumentVersionDAO.getInstance().getVersionContentChecksumByParent(docUuid, verName); String clCheckSum = SecureStore.md5Encode(fsRaw); if (!clCheckSum.equals(stChecksum)) { throw new RepositoryException( "Checksum failure for node '" + docUuid + "' and version '" + verName + "'"); } } catch (NoSuchAlgorithmException e) { log.warn(e.getMessage(), e); } catch (PathNotFoundException e) { throw new RepositoryException("PathNotFound: " + docUuid); } finally { HibernateUtil.close(session); } log.debug("verifyChecksum: void"); }
From source file:ch.admin.vbs.cube.core.webservice.CubeSSLSocketFactory.java
/** * Create a new SSL socket factory./* w ww. j ava 2s . c o m*/ * * @param keyStoreBuilder * the key store builder * @param trustStore * the trust store * @param checkRevocation * <code>true</code> if certificate revocations should be * checked, else <code>false</code> * @throws WebServiceException * if the creation failed */ public static SSLSocketFactory newSSLSocketFactory(KeyStore.Builder keyStoreBuilder, KeyStore trustStore, boolean checkRevocation) throws WebServiceException { KeyManagerFactory keyManagerFactory; try { keyManagerFactory = KeyManagerFactory.getInstance("NewSunX509"); } catch (NoSuchAlgorithmException e) { String message = "Unable to create key manager factory"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } KeyStoreBuilderParameters keyStoreBuilderParameters = new KeyStoreBuilderParameters(keyStoreBuilder); try { keyManagerFactory.init(keyStoreBuilderParameters); } catch (InvalidAlgorithmParameterException e) { String message = "Unable to initialize key manager factory"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } TrustManagerFactory trustManagerFactory; try { trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); } catch (NoSuchAlgorithmException e) { String message = "Unable to create trust manager factory"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } PKIXBuilderParameters pkixBuilderParameters; try { pkixBuilderParameters = new PKIXBuilderParameters(trustStore, null); } catch (KeyStoreException e) { String message = "The trust store is not initialized"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } catch (InvalidAlgorithmParameterException e) { String message = "The trust store does not contain any trusted certificate"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } catch (NullPointerException e) { String message = "The trust store is null"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } pkixBuilderParameters.setRevocationEnabled(checkRevocation); CertPathTrustManagerParameters certPathTrustManagerParameters = new CertPathTrustManagerParameters( pkixBuilderParameters); try { trustManagerFactory.init(certPathTrustManagerParameters); } catch (InvalidAlgorithmParameterException e) { String message = "Unable to initialize trust manager factory"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } SSLContext sslContext; try { sslContext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e) { String message = "Unable to create SSL context"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } try { sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); } catch (KeyManagementException e) { String message = "Unable to initialize SSL context"; LOG.error(message + ": " + e.getMessage()); throw new WebServiceException(message, e); } SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); return sslSocketFactory; }