2013-08-21 93 views
0

我看到的签约问题和加密最终MDM配置文件位置: iOS MDM profile signing, which certificate to use?加密MDM轮廓

我使用充气城堡库进行加密。目前,我在使用scep标识证书加密最终配置文件时被卡住了。

我正面临以下问题。

  1. 从scep响应证书中检索的公钥不是16字节(128位),因此加密失败并带有消息密钥应该是128位。

  2. 如果我可以使用以下代码将公钥更改为16byte,则设备会抛出无效配置文件dailog。

    public static string getKeyMessageDigest(string key) 
        { 
         byte[] ByteData = Encoding.UTF8.GetBytes(key); 
         //MD5 creating MD5 object. 
         MD5 oMd5 = MD5.Create(); 
         byte[] HashData = oMd5.ComputeHash(ByteData); 
    
         //convert byte array to hex format 
         StringBuilder oSb = new StringBuilder(); 
         for (int x = 0; x < HashData.Length; x++) 
         { 
          //hexadecimal string value 
          oSb.Append(HashData[x].ToString("x2")); 
         } 
         return Convert.ToString(oSb); 
        } 
    

有人能帮助我做一些博客或示例代码加密的个人资料?感谢你的帮助。

回答

0

我回答了你的前一个问题的意见:

“我会建议采取OS X服务器MDM实现看看

一般来说加密的个人资料,我记得你应该使用PKCS7包装。所以,你应该看看这个:http://www.cs.berkeley.edu/~jonah/bc/org/bouncycastle/jce/PKCS7SignedData.html

顺便说一句,如果你想得到一般的理解,我建议读一下密码术。直接使用RSA密钥来加密数据,但是它应该用来加密数据对称密钥又被用来加密数据。“

您也可以到这里看看: PKCS#7 Encryption

您的代码将无法正常工作,因为它是 - 不是PKCS7 - 你试图使用MD5(公证书密钥),这不作任何感觉

我真的会真的推荐再读一遍MDM文档和cryptopraphy上的东西。让它错误是很容易的(无论是非工作还是不安全的实现)。

1

我有一个类似的问题。 PFB现在用于加密的工作代码。我正在从设备响应中检索签名证书,从中检索公钥并使用它进行加密。

byte[] request = StreamToByte(ResponseFromDevice); 
var signer = new SignedCms(); 
signer.Decode(request); 
X509Certificate2 certificate = signer.Certificates[0]; 
string xmlData = "payload string to encrypt"; 

Byte[] cleartextsbyte = UTF8Encoding.UTF8.GetBytes(xmlData); 
ContentInfo contentinfo = new ContentInfo(cleartextsbyte); 
EnvelopedCms envelopedCms = new EnvelopedCms(contentinfo); 
CmsRecipient recipient = new CmsRecipient(certificate); 
envelopedCms.Encrypt(recipient); 
string data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>EncryptedPayloadContent</key><data>[ENCRYPTEDDATA]</data><key>PayloadDescription</key><string>For profile enrollment</string><key>PayloadDisplayName</key><string>ProfileName</string><key>PayloadIdentifier</key><string>YourIdentifier</string><key>PayloadOrganization</key><string>YourOrg</string><key>PayloadRemovalDisallowed</key><false/><key>PayloadType</key><string>Configuration</string><key>PayloadUUID</key><string>YourUDID/string><key>PayloadVersion</key><integer>1</integer></dict></plist>"; 
data = data.Replace("[ENCRYPTEDDATA]", Convert.ToBase64String(envelopedCms.Encode())); 
HttpContext.Current.Response.Write(data); 
WebOperationContext.Current.OutgoingResponse.ContentType = "application/x-apple-aspen-config"; 
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK; 
+0

+1你是超级巨星!我一直在努力争取一段时间。我有完全相同的解决方案,但错过了来自EncryptedPayloadContent的Encrypted。那里记录的是什么?!无论如何,感谢您的帮助! –

0

在bouncycastle中,您必须使用CMSAlgorithm.DES_EDE3_CBC对其进行加密。然后像上一步那样签署数据。确保Base64在签名前对加密的有效载荷进行编码。