- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我创建了公共(public)和私有(private) PGP
使用 key org.bouncycastle.openpgp.PGPKeyRingGenerator .进行 GregS 建议的更改后,公钥是 .asc
文件,私钥是 .skr
文件。我首先需要将公钥分发给 Thunderbird 用户,然后再分发给 Outlook 和其他电子邮件客户端的用户。我读了 these instructions for receiving a public key in thunderbird ,但说明只指定了一个 .asc
没有指定 .asc
的内容/结构的扩展名文件。
如何设置以便我下面的(修改过的?)代码创建一个公钥,Thunderbird 的远程用户可以使用它来发送加密的电子邮件,然后可以通过我的私钥解密,私钥也是由(修改过的?)代码创建的以下? 接受的答案将包括分步说明,不仅用于对下面的代码进行任何必要的更改,还用于设置每个远程 Thunderbird 用户以使用下面生成的公钥发送可以由我的应用程序中的私钥,由下面的(已修改?)代码创建。
这是我的 key 生成代码的初稿:
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Date;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.bcpg.sig.Features;
import org.bouncycastle.bcpg.sig.KeyFlags;
import org.bouncycastle.crypto.generators.RSAKeyPairGenerator;
import org.bouncycastle.crypto.params.RSAKeyGenerationParameters;
import org.bouncycastle.openpgp.PGPEncryptedData;
import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPKeyRingGenerator;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyEncryptorBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair;
public class RSAGen {
public static void main(String args[]) throws Exception {
char pass[] = {'h', 'e', 'l', 'l', 'o'};
PGPKeyRingGenerator krgen = generateKeyRingGenerator("alice@example.com", pass);
// Generate public key ring, dump to file.
PGPPublicKeyRing pkr = krgen.generatePublicKeyRing();
ArmoredOutputStream pubout = new ArmoredOutputStream(new BufferedOutputStream(new FileOutputStream("/home/user/dummy.asc")));
pkr.encode(pubout);
pubout.close();
// Generate private key, dump to file.
PGPSecretKeyRing skr = krgen.generateSecretKeyRing();
BufferedOutputStream secout = new BufferedOutputStream(new FileOutputStream("/home/user/dummy.skr"));
skr.encode(secout);
secout.close();
}
public final static PGPKeyRingGenerator generateKeyRingGenerator(String id, char[] pass) throws Exception{
return generateKeyRingGenerator(id, pass, 0xc0);
}
// Note: s2kcount is a number between 0 and 0xff that controls the number of times to iterate the password hash before use. More
// iterations are useful against offline attacks, as it takes more time to check each password. The actual number of iterations is
// rather complex, and also depends on the hash function in use. Refer to Section 3.7.1.3 in rfc4880.txt. Bigger numbers give
// you more iterations. As a rough rule of thumb, when using SHA256 as the hashing function, 0x10 gives you about 64
// iterations, 0x20 about 128, 0x30 about 256 and so on till 0xf0, or about 1 million iterations. The maximum you can go to is
// 0xff, or about 2 million iterations. I'll use 0xc0 as a default -- about 130,000 iterations.
public final static PGPKeyRingGenerator generateKeyRingGenerator(String id, char[] pass, int s2kcount) throws Exception {
// This object generates individual key-pairs.
RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
// Boilerplate RSA parameters, no need to change anything
// except for the RSA key-size (2048). You can use whatever key-size makes sense for you -- 4096, etc.
kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 2048, 12));
// First create the master (signing) key with the generator.
PGPKeyPair rsakp_sign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, kpg.generateKeyPair(), new Date());
// Then an encryption subkey.
PGPKeyPair rsakp_enc = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, kpg.generateKeyPair(), new Date());
// Add a self-signature on the id
PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
// Add signed metadata on the signature.
// 1) Declare its purpose
signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER);
// 2) Set preferences for secondary crypto algorithms to use when sending messages to this key.
signhashgen.setPreferredSymmetricAlgorithms
(false, new int[] {
SymmetricKeyAlgorithmTags.AES_256,
SymmetricKeyAlgorithmTags.AES_192,
SymmetricKeyAlgorithmTags.AES_128
});
signhashgen.setPreferredHashAlgorithms
(false, new int[] {
HashAlgorithmTags.SHA256,
HashAlgorithmTags.SHA1,
HashAlgorithmTags.SHA384,
HashAlgorithmTags.SHA512,
HashAlgorithmTags.SHA224,
});
// 3) Request senders add additional checksums to the message (useful when verifying unsigned messages.)
signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
// Create a signature on the encryption subkey.
PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
// Add metadata to declare its purpose
enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS|KeyFlags.ENCRYPT_STORAGE);
// Objects used to encrypt the secret key.
PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
// bcpg 1.48 exposes this API that includes s2kcount. Earlier versions use a default of 0x60.
PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc, s2kcount)).build(pass);
// Finally, create the keyring itself. The constructor takes parameters that allow it to generate the self signature.
PGPKeyRingGenerator keyRingGen =
new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsakp_sign,
id, sha1Calc, signhashgen.generate(), null,
new BcPGPContentSignerBuilder(rsakp_sign.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), pske);
// Add our encryption subkey, together with its signature.
keyRingGen.addSubKey(rsakp_enc, enchashgen.generate(), null);
return keyRingGen;
}
}
.asc
文件,然后尝试导入
.asc
文件到 Thunderbird,我得到以下错误屏幕:
CentOS 7
上机器,我用
yum install thunderbird
下载了 Thunderbird .您可以通过将以下内容添加到您的
pom.xml
来下载充气城堡。 :
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk15on</artifactId>
<version>1.51</version>
</dependency>
org.bouncycastle.crypto
库,因为它是
bcpg-jdk15on
的依赖项. JRichardSnape 是正确的
RSAKeyGenerationParameters
和
RSAKeyPairGenerator
不在
bcpg-jdk15on.jar
手动下载。 (注意:链接中的版本可能不是最新的。)
但是,这两个类都在自动 Maven 下载中,该下载是由来自 pom.xml
的单个依赖项片段产生的。如上所示。 我这样说是因为没有其他
bouncycastle
我的
pom.xml
中的依赖项.我正在使用 Java 7。
import org.bouncycastle.crypto.params.RSAKeyGenerationParameters;
import org.bouncycastle.crypto.generators.RSAKeyPairGenerator;
import
来自
RSAGen.java
的声明到我上面 OP 中的代码段。我认为问题可能与需要 key 的名称/签名有关。
Enigmail->Key management ->File ->Import keys from file
.这导致出现以下对话框,这似乎表明,在导入 key 时,未对 key 进行签名。因此,似乎没有与
.asc
相关联的姓名或电子邮件地址。导入的文件。之后,该 key 也不会出现在 EnigMail 的 key 列表中。
gpg --gen-key
,我能够让 CentOS 7 终端创建一个 key 对,包括一个公钥,我能够成功地将它导入到 Thunderbird,这样 Thunderbird 现在可以将终端 gpg 生成的公钥与预期的电子邮件收件人相关联。但是,当我采取所有步骤使用公钥从 Thunderbird 发送加密电子邮件时,电子邮件及其附件仍然未加密。我将带有公钥的加密电子邮件从远程 Thunderbird 发送到具有私钥的服务器所采取的步骤是
described in this SuperUser posting .
gpg --gen-key
似乎工作,目前主要的遗留问题,似乎是这个赏金问题的雷鸟部分。我已经在上一段的 SuperUser 问题中发布了解决 Thunderbird 部分的很多进展。您的回答对回答这个问题也大有帮助。
BouncyCastle
-创建了导入 Thunderbird 的 key 。但是,当我使用在
CentOS 7
上创建的 key 时终端使用
gpg --gen-key
,我能够完成以下步骤:
1.) I configured my Thunderbird to manage another (second)
email account I have not been using.
2.) I then created a gpg key for that second account and
configured encryption for that second account in Thunderbird.
3.) I sent an encrypted email containing an attachment from the
first Thunderbird account to the second Thunderbird account.
4.) I was able to see that the attachment remained encrypted in
the second account's inbox until I used the recipient key's
passphrase to decrypt it.
CentOS 7
当我从本编辑中描述的相同“第一个”Thunderbird 帐户向服务器发送电子邮件时,服务器仍在生成未加密的附件。我试图确定这是否是由于
dovecot
中的某些“自动解密”引起的/
postfix
/
mailx
/
gpg
在
CentOS 7
服务器,或者是否由于 Thunderbird 发送器中的某些设置。我正在研究这个。
最佳答案
我将尝试一一解决这些问题:
Java bouncycaSTLe key 环生成
Java 代码确实有效并生成了一个可用的 key 环对。我已经用不同的电子邮件和不同的密码对其进行了测试,没有任何问题。我让第 3 方使用公钥向我发送了一封电子邮件,并使用此 Java 代码生成的私钥成功解密了它。 key 已与以下组合一起使用
CentOS / Thunderbird / pgp
中没有用户 ID组合。同样,导入失败,错误提示
Windows / Outlook / Kleopatra
上没有用户 ID。插件(尽管问题特别引用了 Thunderbird,但已测试)。
gpg --version
显示以下内容
gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)
libgcrypt 1.6.2
gpg --import dummy.asc
gpg --edit-key alice@example.com
check
检查它是否具有用户 ID在
gpg>
迅速的。示例输出:
uid alice@example.com
sig!3 14AEE94A 2015-02-05 [self-signature]
Enigmail->Key management ->File ->Import keys from file
导入 key 似乎已经解决了大部分问题。结合
this related question来自 super 用户的 OP。
Enigmail
-> Preference
-> Sending tab
"Manual encryption settings"
"Always"
在 "confirm before sending"
盒子Adele, the "Friendly OpenPGP Email Robot". Adele accepts OpenPGP messages and replies in an explanatory way to any kind of OpenPGP messages.
adele <at> gnupp <dot> de
关于java - 使用充气城堡创建 Thunderbird 可用的公共(public) PGP key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28245669/
想问一下。有什么区别: LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Conte
我正在使用 RecyclerView 来保存 CardView 列表。在我运行 Lollipop 5.0.2 的设备上,应用程序运行良好并且列表正确显示数据。然而,在其他 Lollipop 之前的设备
简单:我想用 1 个宽度为 0dp 的子项来膨胀父项。 父级 xml: 子类: public class KeyButton extends RelativeLayout implements Vi
我正在尝试创建一个 android 键盘,现在我希望它只是膨胀,即显示来自 main.xml 的线性布局 这是java文件 package keyboard.rob.com; import ... p
我有以下适配器 public class CardAdapter extends RecyclerView.Adapter{ List list; int id; Context context;
我的 main.xml 中目前有一个 DrawerLayout。 AppBarLayout 中包含了一个 Toolbar,然后是一个简单的 LinearLayout 来交换 fragment 。 我导
由于不推荐使用 Kotlin Synthetics,我们正在迁移到 ViewBinding。 我已经尝试了很多关于 ViewStub、ViewBinding 的谷歌搜索和阅读文档,并为 Fragmen
我无法使用 LayoutInflater 扩充 xml(包含 QuickContactBadge 的布局)文件,以便在 ListView 中使用它。它不会产生编译/运行时错误或正确的预期输出。从 XM
我是一名优秀的程序员,十分优秀!