我在这里看到了有关签名和加密最终 mdm 配置文件的问题: iOS MDM profile signing, which certificate to use?
我正在使用 Bouncy CaSTLe 库进行加密。目前,我在使用 scep 身份证书加密最终配置文件时陷入困境。
我面临以下问题。
从 scep 响应证书检索到的公钥不是 16 字节(128 位),因此加密失败,并显示消息“Key should be 128 bit”。
如果我可以使用以下代码将公钥更改为 16 字节,则设备会抛出无效的配置文件日志。
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); }
有人可以帮我提供一些博客或示例代码来加密配置文件吗?感谢您的帮助。
最佳答案
我遇到了类似的问题。 PFB 我现在用来加密的工作代码。我正在从设备响应中检索签名证书,从中检索公钥并使用相同的 key 进行加密。
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;
关于c# - 加密 mdm 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18353914/