java.security.InvalidAlgorithmParameterException Java Examples
The following examples show how to use
java.security.InvalidAlgorithmParameterException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From Android-InsecureBankv2 with MIT License | 6 votes |
public static byte[] aes256decrypt(byte[] ivBytes, byte[] keyBytes, byte[] textBytes) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes); SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, newKey, ivSpec); return cipher.doFinal(textBytes); }
Example #2
Source File: DOMXMLSignatureFactory.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public Transform newTransform(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); } else { try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM"); } } if (params == null) { spi.init(null); } else { spi.init(params, null); } return new DOMTransform(spi); }
Example #3
Source File: DOMXMLSignatureFactory.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); } else { try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM"); } } if (params == null) { spi.init(null); } else { spi.init(params, null); } return new DOMCanonicalizationMethod(spi); }
Example #4
Source File: Wallet.java From blockchain with Apache License 2.0 | 6 votes |
private static byte[] performCipherOperation( int mode, byte[] iv, byte[] encryptKey, byte[] text) throws CipherException { try { IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding"); SecretKeySpec secretKeySpec = new SecretKeySpec(encryptKey, "AES"); cipher.init(mode, secretKeySpec, ivParameterSpec); return cipher.doFinal(text); } catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) { throw new CipherException("Error performing cipher operation", e); } }
Example #5
Source File: ClientTrustManager.java From Openfire with Apache License 2.0 | 6 votes |
public ClientTrustManager(KeyStore trustTrust) { super(); this.trustStore = trustTrust; //Note: A reference of the Collection is used in the CertStore, so we can add CRL's // after creating the CertStore. crls = new ArrayList<>(); CollectionCertStoreParameters params = new CollectionCertStoreParameters(crls); try { crlStore = CertStore.getInstance("Collection", params); } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException ex) { Log.warn("ClientTrustManager: ",ex); } loadCRL(); }
Example #6
Source File: CertManager.java From Spark with Apache License 2.0 | 6 votes |
/** * Check if given certificate is revoked looking on it's CRL (if exist). * @param cert which is validated * @return true if certificate is revoked, false if it isn't or CRL cannot be accessed (because it might not exist). */ public boolean checkRevocation(X509Certificate cert) { boolean revoked = false; try { SparkTrustManager man = new SparkTrustManager(); Collection<X509CRL> crls = man.loadCRL(new X509Certificate[] { cert }); CertificateFactory cf = CertificateFactory.getInstance("X.509"); for (X509CRL crl : crls) { if (crl.isRevoked(cert)) { revoked = true; break; } } } catch (CRLException | CertificateException | IOException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | CertStoreException e) { Log.warning("Cannot check validity", e); } return revoked; }
Example #7
Source File: PKIXParameters.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Sets the {@code Set} of most-trusted CAs. * <p> * Note that the {@code Set} is copied to protect against * subsequent modifications. * * @param trustAnchors a {@code Set} of {@code TrustAnchor}s * @throws InvalidAlgorithmParameterException if the specified * {@code Set} is empty {@code (trustAnchors.isEmpty() == true)} * @throws NullPointerException if the specified {@code Set} is * {@code null} * @throws ClassCastException if any of the elements in the set * are not of type {@code java.security.cert.TrustAnchor} * * @see #getTrustAnchors */ public void setTrustAnchors(Set<TrustAnchor> trustAnchors) throws InvalidAlgorithmParameterException { if (trustAnchors == null) { throw new NullPointerException("the trustAnchors parameters must" + " be non-null"); } if (trustAnchors.isEmpty()) { throw new InvalidAlgorithmParameterException("the trustAnchors " + "parameter must be non-empty"); } for (Iterator<TrustAnchor> i = trustAnchors.iterator(); i.hasNext(); ) { if (!(i.next() instanceof TrustAnchor)) { throw new ClassCastException("all elements of set must be " + "of type java.security.cert.TrustAnchor"); } } this.unmodTrustAnchors = Collections.unmodifiableSet (new HashSet<TrustAnchor>(trustAnchors)); }
Example #8
Source File: DOMXMLSignatureFactory.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public Transform newTransform(String algorithm, TransformParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); } else { try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM"); } } spi.init(params); return new DOMTransform(spi); }
Example #9
Source File: DOMXMLSignatureFactory.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); } else { try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM"); } } if (params == null) { spi.init(null); } else { spi.init(params, null); } return new DOMCanonicalizationMethod(spi); }
Example #10
Source File: EncryptionTest.java From Encryption with MIT License | 6 votes |
@Test public void test_builder() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException { Encryption encryption = new Encryption.Builder() .setKeyLength(128) .setKeyAlgorithm("AES") .setCharsetName("UTF8") .setIterationCount(65536) .setKey("mor€Z€cr€tKYss") .setDigestAlgorithm("SHA1") .setSalt("A beautiful salt") .setBase64Mode(Base64.DEFAULT) .setAlgorithm("AES/CBC/PKCS5Padding") .setSecureRandomAlgorithm("SHA1PRNG") .setSecretKeyType("PBKDF2WithHmacSHA1") .setIv(new byte[] { 29, 88, -79, -101, -108, -38, -126, 90, 52, 101, -35, 114, 12, -48, -66, -30 }) .build(); assertNotNull(encryption); String textToEncrypt = "A text to builder test."; String encryptedText = encryption.encrypt(textToEncrypt); assertNotNull(encryptedText); String decryptedText = encryption.decrypt(encryptedText); assertNotNull(decryptedText); assertEquals(decryptedText, textToEncrypt); }
Example #11
Source File: AndroidKeyStoreRsaUtilsAndroidTest.java From capillary with Apache License 2.0 | 6 votes |
@Test public void testDeleteKeyPair() throws KeyStoreException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchKeyException { try { AndroidKeyStoreRsaUtils.deleteKeyPair(keyStore, KEYCHAIN_ID, false); fail("Did not throw NoSuchKeyException"); } catch (NoSuchKeyException e) { // This is expected. } AndroidKeyStoreRsaUtils.generateKeyPair(context, KEYCHAIN_ID, false); assertEquals(1, keyStore.size()); AndroidKeyStoreRsaUtils.deleteKeyPair(keyStore, KEYCHAIN_ID, false); assertEquals(0, keyStore.size()); }
Example #12
Source File: PKIXParameters.java From j2objc with Apache License 2.0 | 6 votes |
/** * Sets the {@code Set} of most-trusted CAs. * <p> * Note that the {@code Set} is copied to protect against * subsequent modifications. * * @param trustAnchors a {@code Set} of {@code TrustAnchor}s * @throws InvalidAlgorithmParameterException if the specified * {@code Set} is empty {@code (trustAnchors.isEmpty() == true)} * @throws NullPointerException if the specified {@code Set} is * {@code null} * @throws ClassCastException if any of the elements in the set * are not of type {@code java.security.cert.TrustAnchor} * * @see #getTrustAnchors */ public void setTrustAnchors(Set<TrustAnchor> trustAnchors) throws InvalidAlgorithmParameterException { if (trustAnchors == null) { throw new NullPointerException("the trustAnchors parameters must" + " be non-null"); } if (trustAnchors.isEmpty()) { throw new InvalidAlgorithmParameterException("the trustAnchors " + "parameter must be non-empty"); } for (Iterator<TrustAnchor> i = trustAnchors.iterator(); i.hasNext(); ) { if (!(i.next() instanceof TrustAnchor)) { throw new ClassCastException("all elements of set must be " + "of type java.security.cert.TrustAnchor"); } } this.unmodTrustAnchors = Collections.unmodifiableSet (new HashSet<TrustAnchor>(trustAnchors)); }
Example #13
Source File: KeyPairGeneratorSpi.java From RipplePower with Apache License 2.0 | 6 votes |
public void initialize( int strength, SecureRandom random) { this.strength = strength; this.random = random; ECGenParameterSpec ecParams = (ECGenParameterSpec)ecParameters.get(Integers.valueOf(strength)); if (ecParams == null) { throw new InvalidParameterException("unknown key size."); } try { initialize(ecParams, random); } catch (InvalidAlgorithmParameterException e) { throw new InvalidParameterException("key size not configurable."); } }
Example #14
Source File: DOMXPathFilter2Transform.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void init(TransformParameterSpec params) throws InvalidAlgorithmParameterException { if (params == null) { throw new InvalidAlgorithmParameterException("params are required"); } else if (!(params instanceof XPathFilter2ParameterSpec)) { throw new InvalidAlgorithmParameterException ("params must be of type XPathFilter2ParameterSpec"); } this.params = params; }
Example #15
Source File: McElieceKeyPairGeneratorSpi.java From ripple-lib-java with ISC License | 5 votes |
public void initialize(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { kpg = new McElieceCCA2KeyPairGenerator(); super.initialize(params); ECCKeyGenParameterSpec ecc = (ECCKeyGenParameterSpec)params; McElieceCCA2KeyGenerationParameters mccca2KGParams = new McElieceCCA2KeyGenerationParameters(new SecureRandom(), new McElieceCCA2Parameters(ecc.getM(), ecc.getT())); kpg.init(mccca2KGParams); }
Example #16
Source File: JDKAlgorithmParameterGenerator.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
protected void engineInit( AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException { throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation."); }
Example #17
Source File: PBECipherWrapper.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override protected void initCipher(int mode) throws InvalidKeyException, InvalidAlgorithmParameterException, InvalidParameterSpecException { if (Cipher.ENCRYPT_MODE == mode) { ci.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM)); iv = ci.getParameters().getParameterSpec(IvParameterSpec.class) .getIV(); } else { ci.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM), new IvParameterSpec(iv)); } }
Example #18
Source File: DOMExcC14NMethod.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void init(XMLStructure parent, XMLCryptoContext context) throws InvalidAlgorithmParameterException { super.init(parent, context); Element paramsElem = DOMUtils.getFirstChildElement(transformElem); if (paramsElem == null) { this.params = null; this.inclusiveNamespaces = null; return; } unmarshalParams(paramsElem); }
Example #19
Source File: TestCipherKeyWrapperTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private void wrapperAesDESedeKeyTest(String algo, String wrapAlgo, int keySize) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { // Initialization KeyGenerator kg = KeyGenerator.getInstance(algo); if (keySize != -1) { kg.init(keySize); } SecretKey key = kg.generateKey(); wrapTest(algo, wrapAlgo, key, key, Cipher.SECRET_KEY, false); }
Example #20
Source File: SslContext.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
static PrivateKey toPrivateKey(File keyFile, String keyPassword) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, InvalidAlgorithmParameterException, KeyException, IOException { if (keyFile == null) { return null; } return getPrivateKeyFromByteBuffer(PemReader.readPrivateKey(keyFile), keyPassword); }
Example #21
Source File: DOMHMACSignatureMethod.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Creates a <code>DOMHMACSignatureMethod</code> with the specified params * * @param params algorithm-specific parameters (may be <code>null</code>) * @throws InvalidAlgorithmParameterException if params are inappropriate */ DOMHMACSignatureMethod(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { checkParams((SignatureMethodParameterSpec)params); this.params = (SignatureMethodParameterSpec)params; }
Example #22
Source File: PKIX.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns the target subject DN from the first X509Certificate that * is fetched that matches the specified X509CertSelector. */ private static X500Principal getTargetSubject(List<CertStore> stores, X509CertSelector sel) throws InvalidAlgorithmParameterException { X500Principal subject = sel.getSubject(); if (subject != null) { return subject; } X509Certificate cert = sel.getCertificate(); if (cert != null) { subject = cert.getSubjectX500Principal(); } if (subject != null) { return subject; } for (CertStore store : stores) { try { Collection<? extends Certificate> certs = (Collection<? extends Certificate>) store.getCertificates(sel); if (!certs.isEmpty()) { X509Certificate xc = (X509Certificate)certs.iterator().next(); return xc.getSubjectX500Principal(); } } catch (CertStoreException e) { // ignore but log it if (debug != null) { debug.println("BuilderParams.getTargetSubjectDN: " + "non-fatal exception retrieving certs: " + e); e.printStackTrace(); } } } throw new InvalidAlgorithmParameterException ("Could not determine unique target subject"); }
Example #23
Source File: DecrypterImpl.java From data-transfer-project with Apache License 2.0 | 5 votes |
@Override public String decrypt(String encrypted) { try { byte[] decoded = BaseEncoding.base64Url().decode(encrypted); Cipher cipher; switch (transformation) { case AES_CBC_NOPADDING: cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, key, generateIv(cipher)); break; case RSA_ECB_PKCS1: cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.DECRYPT_MODE, key); break; default: throw new AssertionError("How could this happen..."); } byte[] decrypted = cipher.doFinal(decoded); if (decrypted == null || decrypted.length <= cipher.getBlockSize()) { throw new RuntimeException("incorrect decrypted text."); } byte[] data = new byte[decrypted.length - cipher.getBlockSize()]; System.arraycopy(decrypted, cipher.getBlockSize(), data, 0, data.length); return new String(data, Charsets.UTF_8); } catch (BadPaddingException | IllegalBlockSizeException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) { monitor.severe(() -> format("Error decrypting data, length: %s", encrypted.length()), e); throw new RuntimeException(e); } }
Example #24
Source File: SignatureBaseRSA.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** @inheritDoc */ protected void engineSetParameter(AlgorithmParameterSpec params) throws XMLSignatureException { try { this.signatureAlgorithm.setParameter(params); } catch (InvalidAlgorithmParameterException ex) { throw new XMLSignatureException("empty", ex); } }
Example #25
Source File: MultiCertStoreSpi.java From ripple-lib-java with ISC License | 5 votes |
public MultiCertStoreSpi(CertStoreParameters params) throws InvalidAlgorithmParameterException { super(params); if (!(params instanceof MultiCertStoreParameters)) { throw new InvalidAlgorithmParameterException("org.ripple.bouncycastle.jce.provider.MultiCertStoreSpi: parameter must be a MultiCertStoreParameters object\n" + params.toString()); } this.params = (MultiCertStoreParameters)params; }
Example #26
Source File: CryptoPrimitives.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
boolean validateCertificate(Certificate cert) { boolean isValidated; if (cert == null) { return false; } try { KeyStore keyStore = getTrustStore(); PKIXParameters parms = new PKIXParameters(keyStore); parms.setRevocationEnabled(false); CertPathValidator certValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType()); // PKIX ArrayList<Certificate> start = new ArrayList<>(); start.add(cert); CertificateFactory certFactory = CertificateFactory.getInstance(CERTIFICATE_FORMAT); CertPath certPath = certFactory.generateCertPath(start); certValidator.validate(certPath, parms); isValidated = true; } catch (KeyStoreException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | CertificateException | CertPathValidatorException | CryptoException e) { logger.error("Cannot validate certificate. Error is: " + e.getMessage() + "\r\nCertificate" + cert.toString()); isValidated = false; } return isValidated; }
Example #27
Source File: PBECipherWrapper.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override protected void initCipher(int mode) throws InvalidKeyException, InvalidAlgorithmParameterException, InvalidParameterSpecException { if (Cipher.ENCRYPT_MODE == mode) { ci.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM)); iv = ci.getParameters().getParameterSpec(IvParameterSpec.class) .getIV(); } else { ci.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM), new IvParameterSpec(iv)); } }
Example #28
Source File: IndexedCollectionCertStore.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a <code>CertStore</code> with the specified parameters. * For this class, the parameters object must be an instance of * <code>CollectionCertStoreParameters</code>. * * @param params the algorithm parameters * @exception InvalidAlgorithmParameterException if params is not an * instance of <code>CollectionCertStoreParameters</code> */ public IndexedCollectionCertStore(CertStoreParameters params) throws InvalidAlgorithmParameterException { super(params); if (!(params instanceof CollectionCertStoreParameters)) { throw new InvalidAlgorithmParameterException( "parameters must be CollectionCertStoreParameters"); } Collection<?> coll = ((CollectionCertStoreParameters)params).getCollection(); if (coll == null) { throw new InvalidAlgorithmParameterException ("Collection must not be null"); } buildIndex(coll); }
Example #29
Source File: PKIX.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static ValidatorParams checkParams(CertPath cp, CertPathParameters params) throws InvalidAlgorithmParameterException { if (!(params instanceof PKIXParameters)) { throw new InvalidAlgorithmParameterException("inappropriate " + "params, must be an instance of PKIXParameters"); } return new ValidatorParams(cp, (PKIXParameters)params); }
Example #30
Source File: PKIX.java From Bytecoder with Apache License 2.0 | 5 votes |
ValidatorParams(CertPath cp, PKIXParameters params) throws InvalidAlgorithmParameterException { this(params); if (!cp.getType().equals("X.509") && !cp.getType().equals("X509")) { throw new InvalidAlgorithmParameterException("inappropriate " + "CertPath type specified, must be X.509 or X509"); } this.certPath = cp; }