use of java.security.NoSuchProviderException in project robovm by robovm.
the class myCertStore method testCertStore16.
/**
* Test for <code>getType()</code> method
*/
public void testCertStore16() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!initParams()) {
return;
}
CertStore certS;
for (int i = 0; i < dValid.length; i++) {
certS = CertStore.getInstance(dValid[i], dParams);
assertEquals("Incorrect type", certS.getType(), dValid[i]);
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderCol);
assertEquals("Incorrect type", certS.getType(), dValid[i]);
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderColName);
assertEquals("Incorrect type", certS.getType(), dValid[i]);
} catch (NoSuchProviderException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
}
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class myCertStore method testCertStore17.
/**
* Test for <code>getProvider()</code> method
*/
public void testCertStore17() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!initParams()) {
return;
}
CertStore certS;
for (int i = 0; i < dValid.length; i++) {
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderCol);
assertEquals("Incorrect provider", certS.getProvider(), defaultProviderCol);
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderColName);
assertEquals("Incorrect provider", certS.getProvider(), defaultProviderCol);
} catch (NoSuchProviderException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
}
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class myCertStore method testCertStore18.
/**
* Test for <code>getCertStoreParameters()</code> method
*/
public void testCertStore18() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!initParams()) {
return;
}
CertStore certS;
for (int i = 0; i < dValid.length; i++) {
certS = CertStore.getInstance(dValid[i], dParams);
assertEquals("Incorrect parameters", ((CollectionCertStoreParameters) certS.getCertStoreParameters()).getCollection(), ((CollectionCertStoreParameters) dParams).getCollection());
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderCol);
assertEquals("Incorrect parameters", ((CollectionCertStoreParameters) certS.getCertStoreParameters()).getCollection(), ((CollectionCertStoreParameters) dParams).getCollection());
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
try {
certS = CertStore.getInstance(dValid[i], dParams, defaultProviderColName);
assertEquals("Incorrect parameters", ((CollectionCertStoreParameters) certS.getCertStoreParameters()).getCollection(), ((CollectionCertStoreParameters) dParams).getCollection());
} catch (NoSuchProviderException e) {
fail("Unexpected IllegalArgumentException " + e.getMessage());
}
}
}
use of java.security.NoSuchProviderException in project Conversations by siacs.
the class XmppAxolotlMessage method decrypt.
public XmppAxolotlPlaintextMessage decrypt(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
XmppAxolotlPlaintextMessage plaintextMessage = null;
byte[] key = unpackKey(session, sourceDeviceId);
if (key != null) {
try {
if (key.length >= 32) {
int authtaglength = key.length - 16;
Log.d(Config.LOGTAG, "found auth tag as part of omemo key");
byte[] newCipherText = new byte[key.length - 16 + ciphertext.length];
byte[] newKey = new byte[16];
System.arraycopy(ciphertext, 0, newCipherText, 0, ciphertext.length);
System.arraycopy(key, 16, newCipherText, ciphertext.length, authtaglength);
System.arraycopy(key, 0, newKey, 0, newKey.length);
ciphertext = newCipherText;
key = newKey;
}
Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER);
SecretKeySpec keySpec = new SecretKeySpec(key, KEYTYPE);
IvParameterSpec ivSpec = new IvParameterSpec(iv);
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
String plaintext = new String(cipher.doFinal(ciphertext));
plaintextMessage = new XmppAxolotlPlaintextMessage(Config.OMEMO_PADDING ? plaintext.trim() : plaintext, session.getFingerprint());
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchProviderException e) {
throw new CryptoFailedException(e);
}
}
return plaintextMessage;
}
use of java.security.NoSuchProviderException in project nhin-d by DirectProject.
the class CreateSignedPKCS7 method create.
/**
* Creates a pcks7 file from the certificate and key files.
* @param anchorDir :The Directory where the .der files are present.
* @param createFile : The .p7m File name.
* @param metaFile :One XML file as per required specification of TrustBundle metadata schema.
* @param p12certiFile : The .p12 file.
* @param passkey :Pass Key for the .p12 file if present or else it should be blank.
* @param destDir : The Destination folder where the output .p7m files will be created.
* * @return File : Returns the created SignedBundle as a .p7m file.
*/
public File create(String anchorDir, File createFile, File metaFile, boolean metaExists, File p12certiFile, String passKey) {
File pkcs7File = null;
FileOutputStream outStr = null;
InputStream inStr = null;
try {
// Create the unsigned Trust Bundle
CreateUnSignedPKCS7 unSignedPKCS7 = new CreateUnSignedPKCS7();
File unsigned = unSignedPKCS7.create(anchorDir, createFile, metaFile, metaExists);
byte[] unsignedByte = loadFileData(unsigned);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
CMSSignedData unsignedData = new CMSSignedData(unsignedByte);
// Create the certificate array
KeyStore ks = java.security.KeyStore.getInstance("PKCS12", "BC");
ks.load(new FileInputStream(p12certiFile), defaultPwd.toCharArray());
ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = (String) aliases.nextElement();
if (ks.getKey(alias, defaultPwd.toCharArray()) != null && ks.getKey(alias, defaultPwd.toCharArray()) instanceof PrivateKey) {
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build((PrivateKey) ks.getKey(alias, defaultPwd.toCharArray()));
X509CertificateHolder holder = new X509CertificateHolder(ks.getCertificate(alias).getEncoded());
certList.add((X509Certificate) ks.getCertificate(alias));
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()).build(sha1Signer, holder));
}
}
Store certStores = new JcaCertStore(certList);
gen.addCertificates(certStores);
CMSSignedData sigData = gen.generate(new CMSProcessableByteArray(unsignedData.getEncoded()), true);
//SignedData encapInfo = SignedData.getInstance(sigData.getContentInfo().getContent());
pkcs7File = getPKCS7OutFile(createFile);
outStr = new FileOutputStream(pkcs7File);
outStr.write(sigData.getEncoded());
} catch (CMSException e) {
// e.printStackTrace(System.err);
return null;
} catch (IOException e) {
// e.printStackTrace(System.err);
return null;
} catch (KeyStoreException e) {
// e.printStackTrace(System.err);
return null;
} catch (NoSuchProviderException e) {
// e.printStackTrace(System.err);
return null;
} catch (NoSuchAlgorithmException e) {
// e.printStackTrace(System.err);
return null;
} catch (CertificateException e) {
// e.printStackTrace(System.err);
return null;
} catch (UnrecoverableKeyException e) {
// e.printStackTrace(System.err);
return null;
} catch (OperatorCreationException e) {
// e.printStackTrace(System.err);
return null;
} catch (Exception e) {
// e.printStackTrace(System.err);
return null;
} finally {
IOUtils.closeQuietly(outStr);
IOUtils.closeQuietly(inStr);
}
return pkcs7File;
}
Aggregations