- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我们的组织为多个客户管理稳定的 iOS 应用程序,这意味着要处理大量不同的开发人员身份证书和推送通知证书。
我在 Bouncy Castle C# Crypto API 上取得了成功在简化推送通知的证书和私钥管理方面,essentially eliminating the need for the Keychain for all our push notification certificates .
我想将其扩展到开发人员身份证书。目标是将每个开发人员身份的所有私钥和证书信息存储在数据库中。然后,当需要配置新的开发人员或构建机器时,服务器端代码可以将所有证书和私钥打包到一个 p12 存档中,并使用一个密码将其导入目标 Mac 的钥匙串(keychain)。
不幸的是,Mac Keychain 不喜欢我生成的 p12 文件。这很烦人,因为我可以成功地将这些文件导入到 Windows 证书管理器中。
我正在使用的代码(重要部分)如下所示:
private byte[] GetP12Bytes(List<DevIdentity> identities, string password)
{
Pkcs12Store store = new Pkcs12Store();
foreach(DevIdentity ident in identities)
{
// Easiest to create a Bouncy Castle cert by converting from .NET
var dotNetCert = new X509Certificate2(ident.CertificateBytes);
// This method (not shown) parses the CN= attribute out of the cert's distinguished name
string friendlyName = GetFriendlyName(dotNetCert.Subject);
// Now reconstitute the private key from saved value strings
BigInteger modulus = new BigInteger(ident.PrivateKey.Modulus);
BigInteger publicExponent = new BigInteger(ident.PrivateKey.PublicExponent);
BigInteger privateExponent = new BigInteger(ident.PrivateKey.Exponent);
BigInteger p = new BigInteger(ident.PrivateKey.P);
BigInteger q = new BigInteger(ident.PrivateKey.Q);
BigInteger dP = new BigInteger(ident.PrivateKey.DP);
BigInteger dQ = new BigInteger(ident.PrivateKey.DQ);
BigInteger qInv = new BigInteger(ident.PrivateKey.QInv);
RsaKeyParameters kp = new RsaPrivateCrtKeyParameters(modulus, publicExponent, privateExponent, p, q, dP, dQ, qInv);
AsymmetricKeyEntry privateKey = new AsymmetricKeyEntry(kp);
// Now let's convert to a Bouncy Castle cert and wrap it for packaging
Org.BouncyCastle.X509.X509Certificate cert = DotNetUtilities.FromX509Certificate(dotNetCert);
X509CertificateEntry certEntry = new X509CertificateEntry(cert);
// Set the private key and certificate into the store
store.SetCertificateEntry(friendlyName, certEntry);
store.SetKeyEntry(ident.PrivateKeyName, privateKey, new X509CertificateEntry[] { certEntry });
}
using (MemoryStream ms = new MemoryStream())
{
store.Save(ms, password.ToCharArray(), new SecureRandom());
ms.Flush();
byte[] p12Bytes = ms.ToArray();
return p12Bytes;
}
}
正如我所说,这非常适合在 Windows 上导入,但在导入到 Mac Keychain 时失败并出现非常普遍的错误。
加载钥匙串(keychain)生成的 p12 文件和我自己生成的 p12 文件时,我可以看到一个主要区别,但我不知道这是否是原因。
如果我将 Mac Keychain 生成的 p12 加载到 Bouncy CaSTLe PKCS12Store 中,然后检查 key ,在 Keychain p12 上,证书和私钥都具有 key 为“1.2.840.113549.1.9.21”的属性具有等效值(具有值 #af8a1d6891efeb32756c12b7bdd96b5ec673e11e 的 DerOctetString)。
如果我对生成的 p12 文件执行相同操作,则私钥包含“1.2.840.113549.1.9.21”属性,但证书不包含。
如果我Google "1.2.840.113549.1.9.21" , 我 find out that this OID means PKCS_12_LOCAL_KEY_ID .我唯一的理论是钥匙串(keychain)依靠它来匹配证书和私钥,而我生成的文件没有这个,所以它失败了。
但是,我已经尝试将这些值添加到哈希表,然后使用采用属性哈希表的 CertificateEntry 构造函数。如果我这样做,然后保存字节,然后重新加载字节,则该属性再次丢失。
所以我很困惑。也许这个属性是 Bouncy CaSTLe API 中的一个小故障?也许我做错了什么。也许钥匙串(keychain)对传入的 p12 文件有荒谬的非标准要求。无论如何,我们将不胜感激。
最佳答案
BouncyCaSTLe 的 Pkcs12Store 负责为您设置 Friendly Name 和 Local Key ID 属性(或者至少在大约 2011 年 4 月的 1.7 版本中这样做)。我的猜测是您一定使用了旧版本,但它不起作用。
以下是我将 iPhone 开发人员身份保存到 Pkcs12Store 实例的方式(省略了额外的内容和安全性):
var store = new Pkcs12Store();
// pairs is IEnumerable<Tuple<X509Certificate, AsymmetricKeyParameter>>
foreach (var pair in pairs)
{
var cn = pair.Item1.SubjectDN
.GetValueList(X509Name.CN).OfType<string>().Single();
var certEntry = new X509CertificateEntry(pair.Item1);
store.SetCertificateEntry(cn, certEntry);
var keyEntry = new AsymmetricKeyEntry(pair.Item2);
store.SetKeyEntry("Developer Name", keyEntry, new[] { certEntry });
}
store.Save(stream, string.Empty.ToArray(), new SecureRandom());
在 OS X 10.7 上的 Keychain Access.app 中导入商店正确地将证书和私钥放入钥匙串(keychain)中,并将证书放入 UI 中的私钥中,就像 Keychain Access 本身生成的证书和 key 一样。
附带说明一下,Pkcs12Store 似乎使用证书的公钥来生成证书和 key 条目共享的 LocalKeyId 属性的值。
可以查看Pkcs12Store源码的相关部分here .
关于c# - 让 Apple Keychain 识别 Bouncy CaSTLe .NET 创建的 PKCS12 (.p12) 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4947419/
我有一个案例需要使用 OpenPGP 加密一些文件。我正在使用 Bouncy CaSTLe 这样做。 据我了解,Bouncy CaSTLe 加密可以通过两种方式在 Java 中使用: 我将 Bounc
我想创建一个使用 Bouncy CaSTLe(版本 1.59)实现的 signedAndEnvelopedData (PKCS #7) 数据。 在 Bouncy CaSTLe 中,接口(interfa
我发现了一些使用 Bouncy CaSTLe 加密数据的代码,但我找不到任何文档来说明正在使用哪种算法来加密数据或 key 使用了多少位。我也找不到 Bouncy CaSTLe 的论坛。有谁知道它使用
这个问题已经有答案了: bouncycastle + JBoss AS7: JCE cannot authenticate the provider BC (5 个回答) 已关闭10 年前。 我使用的
我的系统中有一个进程将接收随机纯文本或密文输入。由于性能不是问题,我打算尝试解密所有传入的输入,使用如下伪代码: //get the input, either a plain text, or ci
我一直认为使用 ECFieldElement 对象而不是 BigIntegers 对指数执行算术运算更合适,但根据我的测试,这样做会产生不正确的结果。 测试例程(JUnit): class Arith
我正在尝试从 smime.p7s 文件中读取证书,证书链是: Baltimora Cyber Trust --> DigitPA --> Aruba PEC 因此,当我尝试提取时,我只检索到最后两
我正试图找到一种方法来消除移动设备上的 flex 滚动行为(例如,当下面没有内容可滚动时,您仍然可以滚动内容并将内容滚动到顶部,当释放时它会弹跳返回) 我的html结构是这样的
我正在使用来自Codyhouse的这个很棒的弹性过滤器但我一生都无法弄清楚如何让它自动运行,即自行翻转并仍然接受用户点击事件。 jsfiddle ...谢谢。 jQuery(document).rea
考虑正数的以下定义: 如果从左到右它的数字永远不会变小,则该数字是非递减的。例如,12345和 3388 是非递减的。 如果从左到右它的数字从不变大,则该数是非递增的。例如,987542 和881个没
我使用 WPF ScrollViewer 来托管一些控件。我真的很希望它能像在触摸设备上那样进行交互,当你将它拉得太远时,它会慢慢回到原位。 它没有滚动条 - 我使用此代码通过单击和拖动手动滚动鼠标:
我有一个使用 Bouncy CaSTLe 进行 PGP 解密的应用程序,它在过去 8 个月左右的时间里运行没有任何问题,而在过去的 2 天里突然出现了一个问题,其中 GetDataStream 方法抛
我有一个 PEM 或 DER 私钥,一个现有的 key 。如何加载此 key PrivateKeyFactory.createKey or into an AsymmetricCipherKeyPai
我正在查看 Bouncy CaSTLe,看看它的哈希算法的性能与 .NET Framework 的性能相比如何,它看起来不太好; MD5 实现比 .NET 慢 6 倍左右,SHA256 实现比 .NE
我正在寻找 Bouncy CaSTLe PGP“签名和加密”的实现。理想情况下,如果这有什么不同的话,只需一次操作即可。 我已经采取了 encrypt example和 signing example
我正在按照此处的示例:http://www.baeldung.com/java-bouncy-castle 我有几个问题: public static byte[] encryptData(byte[
我正在尝试用 C# 签署比特币交易。我有 2 位代码正在尝试完成。我可以使用 Bouncy caSTLe 创建一组私钥和公钥。我可以将其转换为钱包导入格式。 我还可以从 ECDSA 公钥生成比特币地址
我正在查看 Bouncy CaSTLe,看看它的哈希算法的性能与 .NET Framework 的性能相比如何,它看起来不太好; MD5 实现比 .NET 慢 6 倍左右,SHA256 实现比 .NE
我很确定没有,但我想确认 Bouncy CaSTLe for Java 中的 SCrypt 实现 SCrypt.generate() 是否在结果中包含参数(例如NodeJS 的实现确实如此)。 最佳答
我正在使用 bouncy caSTLe 1.48 通过 OCSP 验证证书验证。效果很好。但我使用 Ocsp Url 作为静态变量,我想从证书中读取它。证书中的 URL 写为Authority Inf
我是一名优秀的程序员,十分优秀!