List of usage examples for java.security NoSuchAlgorithmException NoSuchAlgorithmException
public NoSuchAlgorithmException(Throwable cause)
From source file:at.gv.egiz.bku.local.stal.LocalSecureViewer.java
private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { mdAlg = "SHA-1"; } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { mdAlg = "SHA-256"; } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { mdAlg = "SHA-224"; } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { mdAlg = "SHA-224"; } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { mdAlg = "SHA-384"; } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { mdAlg = "SHA-512"; } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { mdAlg = "MD2"; } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { mdAlg = "MD5"; } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { mdAlg = "RIPEMD160"; } else {/* w w w .j a v a 2 s .co m*/ throw new NoSuchAlgorithmException( "Failed to verify digest value: unsupported digest algorithm " + mdAlg); } MessageDigest md; try { md = MessageDigest.getInstance(mdAlg); } catch (CryptoException e) { throw new NoSuchAlgorithmException(e); } return md.digest(hashDataInput); }
From source file:at.gv.egiz.bku.slcommands.impl.cms.Signature.java
private void setAlgorithmIDs(X509Certificate signingCertificate, boolean useStrongHash) throws NoSuchAlgorithmException { AlgorithmMethodFactory amf = new AlgorithmMethodFactoryImpl(signingCertificate, useStrongHash); signatureAlgorithmURI = amf.getSignatureAlgorithmURI(); signatureAlgorithm = amf.getSignatureAlgorithmID(); if (digestAlgorithm != null) { if (AlgorithmID.sha1.equals(digestAlgorithm)) { digestAlgorithmURI = DigestMethod.SHA1; } else if (AlgorithmID.sha256.equals(digestAlgorithm)) { digestAlgorithmURI = DigestMethod.SHA256; } else if (AlgorithmID.sha512.equals(digestAlgorithm)) { digestAlgorithmURI = DigestMethod.SHA512; } else if (AlgorithmID.ripeMd160.equals(digestAlgorithm)) { digestAlgorithmURI = DigestMethod.RIPEMD160; } else {/*from w ww . ja v a2 s . co m*/ throw new NoSuchAlgorithmException("Algorithm '" + digestAlgorithm + "' not supported."); } } else { digestAlgorithmURI = amf.getDigestAlgorithmURI(); digestAlgorithm = amf.getDigestAlgorithmID(); } }
From source file:org.eclipse.lyo.client.oslc.OslcClient.java
/** * Looks up and select an installed security context provider * /*from w w w. j a va 2 s. c o m*/ * @return An installed SSLContext Provider * @throws NoSuchAlgorithmException when no suitable provider is installed */ private SSLContext findInstalledSecurityContext() throws NoSuchAlgorithmException { // walks through list of secure socked protocols and picks the first found // the list is arranged in level of security order for (String aSecuredProtocol : SECURE_SOCKET_PROTOCOL) { try { return SSLContext.getInstance(aSecuredProtocol); } catch (NoSuchAlgorithmException e) { continue; } } throw new NoSuchAlgorithmException("No suitable secured socket provider is installed"); //$NON-NLS-1$ }
From source file:com.netscape.cms.logging.LogFile.java
private void setupSigning() throws EBaseException { try {//from w w w . j av a 2 s. co m Provider[] providers = java.security.Security.getProviders(); int ps = providers.length; for (int i = 0; i < ps; i++) { CMS.debug("LogFile: provider " + i + "= " + providers[i].getName()); } CryptoManager cm = CryptoManager.getInstance(); // find CertServer's private key X509Certificate cert = cm.findCertByNickname(mSAuditCertNickName); if (cert != null) { CMS.debug("LogFile: setupSignig(): found cert:" + mSAuditCertNickName); } else { CMS.debug("LogFile: setupSignig(): cert not found:" + mSAuditCertNickName); } mSigningKey = cm.findPrivKeyByCert(cert); String sigAlgorithm; if (mSigningKey.getAlgorithm().equalsIgnoreCase("RSA")) { sigAlgorithm = "SHA-256/RSA"; } else if (mSigningKey.getAlgorithm().equalsIgnoreCase("EC")) { sigAlgorithm = "SHA-256/EC"; } else { throw new NoSuchAlgorithmException("Unknown private key type"); } CryptoToken savedToken = cm.getThreadToken(); try { CryptoToken keyToken = ((org.mozilla.jss.pkcs11.PK11PrivKey) mSigningKey).getOwningToken(); cm.setThreadToken(keyToken); mSignature = java.security.Signature.getInstance(sigAlgorithm, CRYPTO_PROVIDER); } finally { cm.setThreadToken(savedToken); } mSignature.initSign(mSigningKey); // get the last signature from the currently-opened file String entry = getLastSignature(mFile); if (entry != null) { mSignature.update(entry.getBytes("UTF-8")); mSignature.update(LINE_SEP_BYTE); } // Always start off with a signature. That way, even if there // were problems with the log file we inherited, we will // get a fresh start with this instance. pushSignature(); } catch (NotInitializedException nie) { setupSigningFailure("BASE_CRYPTOMANAGER_UNINITIALIZED", nie); } catch (ObjectNotFoundException onfe) { setupSigningFailure("LOG_SIGNING_CERT_NOT_FOUND", onfe); } catch (TokenException te) { setupSigningFailure("BASE_TOKEN_ERROR_0", te); } catch (NoSuchAlgorithmException nsae) { setupSigningFailure("LOG_NO_SUCH_ALGORITHM_0", nsae); } catch (NoSuchProviderException nspe) { setupSigningFailure("BASE_PROVIDER_NOT_SUPPORTED", nspe); } catch (InvalidKeyException ike) { setupSigningFailure("BASE_INVALID_KEY", ike); } catch (SignatureException se) { setupSigningFailure("LOG_SIGNING_OP_FAILED", se); } catch (UnsupportedEncodingException uee) { setupSigningFailure("LOG_UNEXPECTED_EXCEPTION", uee); } catch (IOException ioe) { setupSigningFailure("LOG_UNEXPECTED_EXCEPTION", ioe); } catch (Exception e) { setupSigningFailure("LOG_UNEXPECTED_EXCEPTION", e); } }
From source file:cl.nic.dte.util.XMLUtil.java
public static AUTORIZACIONDocument generateAuthorization(AUTORIZACIONDocument template, PrivateKey pKey) throws NoSuchAlgorithmException, SignatureException, TransformerException, InvalidKeyException, IOException {/*from w w w. j av a 2 s . co m*/ // Generation of keys KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(1024); KeyPair kp = kpg.generateKeyPair(); CAFType caf = template.getAUTORIZACION().getCAF(); CAFType.DA.RSAPK rsapk = caf.getDA().addNewRSAPK(); rsapk.setM(((RSAPublicKey) kp.getPublic()).getModulus().toByteArray()); rsapk.setE(((RSAPublicKey) kp.getPublic()).getPublicExponent().toByteArray()); ResourceBundle labels = ResourceBundle.getBundle("cl.nic.dte.resources.VerifyResults"); Signature sig = null; if (pKey.getAlgorithm().equals("RSA")) { sig = Signature.getInstance("SHA1withRSA"); caf.addNewFRMA().setAlgoritmo("SHA1withRSA"); } else if (pKey.getAlgorithm().equals("DSA")) { sig = Signature.getInstance("SHA1withDSA"); caf.addNewFRMA().setAlgoritmo("SHA1withDSA"); } else { throw new NoSuchAlgorithmException( labels.getString("ALGORITHM_NOT_SUPPORTED").replaceAll("%1", pKey.getAlgorithm())); } template.getAUTORIZACION() .setRSASK("-----BEGIN RSA PRIVATE KEY-----\n" + new String(Base64.encodeBase64(kp.getPrivate().getEncoded(), true)) + "-----END RSA PRIVATE KEY-----\n"); template.getAUTORIZACION() .setRSAPUBK("-----BEGIN RSA PUBLIC KEY-----\n" + new String(Base64.encodeBase64(kp.getPublic().getEncoded(), true)) + "-----END RSA PUBLIC KEY-----\n"); sig.initSign(pKey); sig.update(XMLUtil.getCleaned(caf.getDA())); caf.getFRMA().setByteArrayValue(Base64.encodeBase64(sig.sign())); return template; }
From source file:com.lp.alm.lyo.client.oslc.OslcClient.java
/** * Looks up and select an installed security context provider * * @return An installed SSLContext Provider * @throws NoSuchAlgorithmException when no suitable provider is installed *///from www. j a va2s . com private SSLContext findInstalledSecurityContext() throws NoSuchAlgorithmException { if (configuredSecureSocketProtocol != null) { SSLContext sslContext = null; try { sslContext = SSLContext.getInstance(configuredSecureSocketProtocol); } catch (NoSuchAlgorithmException e) { // Ignore Exception, we will try other default values below } if (sslContext != null) { return sslContext; } } // walks through list of secure socked protocols and picks the first found // the list is arranged in level of security order for (String aSecuredProtocol : SECURE_SOCKET_PROTOCOL) { try { return SSLContext.getInstance(aSecuredProtocol); } catch (NoSuchAlgorithmException e) { continue; } } throw new NoSuchAlgorithmException("No suitable secured socket provider is installed"); //$NON-NLS-1$ }
From source file:com.netscape.cmsutil.crypto.CryptoUtil.java
public static PKCS10 createCertificationRequest(String subjectName, KeyPair keyPair, Extensions exts) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, CertificateException, SignatureException { String method = "CryptoUtil: createCertificationRequest: "; String alg = "SHA256withRSA"; PublicKey pubk = keyPair.getPublic(); X509Key key = convertPublicKeyToX509Key(pubk); if (pubk instanceof RSAPublicKey) { alg = "SHA256withRSA"; } else if (isECCKey(key)) { alg = "SHA256withEC"; } else {//from w w w.ja v a 2 s. c o m throw new NoSuchAlgorithmException(method + alg); } return createCertificationRequest(subjectName, key, (org.mozilla.jss.crypto.PrivateKey) keyPair.getPrivate(), alg, exts); }
From source file:nl.nn.adapterframework.pipes.ChecksumPipe.java
protected ChecksumGenerator createChecksumGenerator() throws NoSuchAlgorithmException { if (CHECKSUM_MD5.equals(getType())) { return new MessageDigestChecksumGenerator(getType()); } else if (CHECKSUM_CRC32.equals(getType())) { return new ZipChecksumGenerator(new CRC32()); } else if (CHECKSUM_ADLER32.equals(getType())) { return new ZipChecksumGenerator(new Adler32()); } else if (CHECKSUM_SHA.equals(getType())) { return new MessageDigestChecksumGenerator(getType()); } else {//w ww . j a v a 2 s . co m throw new NoSuchAlgorithmException("unsupported algorithm [" + getType() + "]"); } }
From source file:org.apache.tajo.engine.function.string.Digest.java
String digest(byte[] data, String type) throws NoSuchAlgorithmException { if ("SHA1".equalsIgnoreCase(type) == true) { MessageDigest md = MessageDigest.getInstance("SHA-1"); return new String(Hex.encodeHex(md.digest(data))); } else if ("SHA256".equalsIgnoreCase(type) == true) { return DigestUtils.sha256Hex(data); } else if ("SHA384".equalsIgnoreCase(type) == true) { return DigestUtils.sha384Hex(data); } else if ("SHA512".equalsIgnoreCase(type) == true) { return DigestUtils.sha512Hex(data); } else if ("MD5".equalsIgnoreCase(type) == true) { return DigestUtils.md5Hex(data); } else if ("MD2".equalsIgnoreCase(type) == true) { MessageDigest md = MessageDigest.getInstance("MD2"); return new String(Hex.encodeHex(md.digest(data))); }/*from w w w . j a v a 2 s . c o m*/ throw new NoSuchAlgorithmException("Not supported DigestType"); }
From source file:org.devproof.portal.core.module.common.util.httpclient.ssl.EasyX509TrustManager.java
/** * Constructor for EasyX509TrustManager. */// w w w. j a v a2 s. c o m public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { super(); TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); factory.init(keystore); TrustManager[] trustmanagers = factory.getTrustManagers(); if (trustmanagers.length == 0) { throw new NoSuchAlgorithmException("no trust manager found"); } standardTrustManager = (X509TrustManager) trustmanagers[0]; }