use of org.bouncycastle.mail.smime.SMIMEEnveloped in project nhin-d by DirectProject.
the class MessagaeDecryptor method main.
public static void main(String[] args) {
try {
final KeyStore store = KeyStore.getInstance("pkcs12");
store.load(FileUtils.openInputStream(new File("/users/gm2552/Desktop/ops.p12")), "".toCharArray());
final String alias = store.aliases().nextElement();
final PrivateKey entry = (PrivateKey) store.getKey(alias, "".toCharArray());
final X509Certificate cert = (X509Certificate) store.getCertificate(alias);
/*
for (String arg :args)
{
if (arg )
}
*/
//String encryptedStuff = FileUtils.readFileToString(new File("users/gm2552/Desktop/cry.eml"));
InputStream inStream = FileUtils.openInputStream(new File("/users/gm2552/Desktop/cry2.eml"));
MimeBodyPart part = new MimeBodyPart(inStream);
final SMIMEEnveloped m = new SMIMEEnveloped(part);
RecipientId recId = new RecipientId();
recId.setIssuer(cert.getIssuerX500Principal().getEncoded());
recId.setSerialNumber(cert.getSerialNumber());
final RecipientInformationStore recipients = m.getRecipientInfos();
final DirectRecipientInformation recipient = new SplitDirectRecipientInformationFactory().createInstance(recipients.get(recId), m);
final byte[] decryptedPayload = recipient.getDecryptedContent(entry);
System.out.println("Alg OID: " + m.getEncryptionAlgOID());
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.bouncycastle.mail.smime.SMIMEEnveloped in project nhin-d by DirectProject.
the class MessageEncEnvInfoInspector method main.
public static void main(String[] args) {
if (args.length == 0) {
//printUsage();
System.exit(-1);
}
String messgefile = null;
for (int i = 0; i < args.length; i++) {
String arg = args[i];
// Options
if (!arg.startsWith("-")) {
System.err.println("Error: Unexpected argument [" + arg + "]\n");
//printUsage();
System.exit(-1);
} else if (arg.equalsIgnoreCase("-msgFile")) {
if (i == args.length - 1 || args[i + 1].startsWith("-")) {
System.err.println("Error: Missing message file");
System.exit(-1);
}
messgefile = args[++i];
} else if (arg.equals("-help")) {
//printUsage();
System.exit(-1);
} else {
System.err.println("Error: Unknown argument " + arg + "\n");
//printUsage();
System.exit(-1);
}
}
if (messgefile == null) {
System.err.println("Error: missing message file\n");
}
InputStream inStream = null;
try {
inStream = FileUtils.openInputStream(new File(messgefile));
final SMIMEEnveloped env = new SMIMEEnveloped(new MimeMessage(null, inStream));
String OID = env.getEncryptionAlgOID();
System.out.println("Encryption OID: " + OID);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(inStream);
}
}
use of org.bouncycastle.mail.smime.SMIMEEnveloped in project nhin-d by DirectProject.
the class DefaultDirectRecipientInformationFactory_createInstanceTest method createSMIMEEnv.
protected SMIMEEnveloped createSMIMEEnv() throws Exception {
// get the cert
final X509Certificate cert = TestUtils.getExternalCert("user1");
// create an encrypted message
final MimeEntity entity = new MimeEntity();
entity.setText("Hello world.");
entity.setHeader(MimeStandard.ContentTypeHeader, "text/plain");
entity.setHeader(MimeStandard.ContentTransferEncodingHeader, "7bit");
final SMIMECryptographerImpl encryptor = new SMIMECryptographerImpl();
return new SMIMEEnveloped(encryptor.encrypt(entity, Arrays.asList(cert)));
}
use of org.bouncycastle.mail.smime.SMIMEEnveloped in project nhin-d by DirectProject.
the class DefaultDirectRecipientInformation_getDecryptedContentTest method createSMIMEEnv.
protected SMIMEEnveloped createSMIMEEnv() throws Exception {
// get the cert
encCert = (X509CertificateEx) TestUtils.getInternalCert("user1");
// create an encrypted message
final MimeEntity entity = new MimeEntity();
entity.setText("Hello world.");
entity.setHeader(MimeStandard.ContentTypeHeader, "text/plain");
entity.setHeader(MimeStandard.ContentTransferEncodingHeader, "7bit");
final SMIMECryptographerImpl encryptor = new SMIMECryptographerImpl();
return new SMIMEEnveloped(encryptor.encrypt(entity, Arrays.asList((X509Certificate) encCert)));
}
use of org.bouncycastle.mail.smime.SMIMEEnveloped in project nhin-d by DirectProject.
the class SplitDirectRecipientInformationFactory_createInstanceTest method testInstanceTest_configedProvider_assertConfigedProvider.
public void testInstanceTest_configedProvider_assertConfigedProvider() throws Exception {
final SMIMEEnveloped env = createSMIMEEnv();
final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory("SensitiveProv", "NonSenProv");
final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
assertEquals("NonSenProv", recInfo.encProvider);
assertEquals("SensitiveProv", recInfo.keyEncProvider);
}
Aggregations