I've an error when i try to encrypt a mail using PGP
The error:
**java.security.NoSuchProviderException: No provider configured for PGP**
at net.suberic.crypto.EncryptionManager.getEncryptionUtils(EncryptionManager.java:106)
at tools.Encryption.encrypt(Encryption.java:29)
at core.mails.HtmlSeriesUploadingMail.sendMail(HtmlSeriesUploadingMail.java:93)
at core.services.MailService.run(MailService.java:71)
at java.lang.Thread.run(Unknown Source)
I saw that i need some library in my classpath so here is my classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/mail.jar"/>
<classpathentry kind="lib" path="lib/wrapper.jar"/>
<classpathentry kind="lib" path="lib/mysql.jar"/>
<classpathentry kind="lib" path="lib/pd4ml.jar"/>
<classpathentry kind="lib" path="lib/ini4j-0.5.1.jar"/>
<classpathentry kind="lib" path="lib/jdom-2.0.4.jar"/>
<classpathentry kind="lib" path="lib/bcmail-jdk14-139.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk14-139.jar"/>
<classpathentry kind="lib" path="lib/javamail-crypto_060622.jar"/>
<classpathentry kind="lib" path="lib/javamail-crypto-bouncycastle-smime.jar"/>
<classpathentry kind="lib" path="lib/ss_css2.jar"/>
<classpathentry kind="lib" path="lib/certpath-api-compat.jar"/>
<classpathentry kind="lib" path="lib/cryptix-message-api.jar"/>
<classpathentry kind="lib" path="lib/cryptix-openpgp-provider.jar"/>
<classpathentry kind="lib" path="lib/cryptix-pki-api.jar"/>
<classpathentry kind="lib" path="lib/cryptix-jce-provider-2.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
And here's my code to encrypt:
public MimeMessage encrypt(Session session, MimeMessage mimeMessage, InternetAddress recipient) throws Exception {
// get the PGP EncryptionUtilities
EncryptionUtils pgpUtils = EncryptionManager.getEncryptionUtils(EncryptionManager.PGP);
// load the PGP keystore from the given file.
EncryptionKeyManager pgpKeyMgr = pgpUtils.createKeyManager();
pgpKeyMgr.loadPublicKeystore(new FileInputStream(new File(SystemData.getWatchDogConfig() + "test.asc")), null);
// get the PGP public key for encryption
java.security.Key pgpKey = pgpKeyMgr.getPublicKey((String) pgpKeyMgr.publicKeyAliases().iterator().next());
// encrypt the message
return pgpUtils.encryptMessage(session, mimeMessage, pgpKey);
}
I don't know what i should do... I begin with javamail and bouncycastle.
The exception NoSuchProviderException
is thrown by EncryptionManager
when it cannot find the provider specified in getEncryptionUtils
. The providers are loaded statically in EncryptionManager
class by retrieving them from the file META-INF/javamail-crypto.providers
. So, in order for EncryptionManager
to load PGP provider you will have to add a javamail-crypto.providers
file into your META-INF
folder with the following line:
protocol=PGP;class=net.suberic.crypto.PGPEncryptionUtils