我有一個錯誤發送加密郵件用JavaMail當我嘗試使用PGP使用PGP
錯誤加密郵件:
**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)
我看到了,我需要一些圖書館在我的類路徑,以便這裏是我的類路徑:
<?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>
,這裏是我的代碼進行加密:
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);
}
我不知道該怎麼辦......我從javamail和bouncycastle開始。
它仍然無法正常工作 –
@Olivier Wathieu:你能送你的代碼迄今爲止已經嘗試過,完整的堆棧跟蹤? –
我編輯了我的問題。感謝您幫助我的方式;) –