最近我开始从事 Apple 应用商店收据验证工作,由于旧版
/verifyReceipt
端点已弃用,我决定采用 设备上验证。所描述的指南给出了 MacOS
的分步解决方案,但是我们希望使用 NodeJs 在后端服务中执行此验证。为此,需要对 PCKS7#
容器中定义的信息进行解码。在这里,我的知识很短,因为我无法检索这些信息(例如receipt_creation_data
,bundle_id
)我设法将收据从PCKS7
转换为ASN.1
,但找不到从中检索实际键值的方法它。我尝试了几个库,例如 node-forge
、asn1js
、asn1.js
。我发现真正有用的是这些资源:
PKCS#7
转换为 ASN.1
如何使用 Javascript 从 ASN.1 检索诸如
bundle_id
或 receipt_creation_date
之类的信息?
// Base64 string of ASN.1 or PKCS#7 data
const base64Data = '...'; // Replace with your Base64 data
// Decode Base64
const binaryData = atob(base64Data);
// Transform the binary string into a byte array
const byteArray = binaryData.split('').map(char => char.charCodeAt(0));
// Now you have the `byteArray` containing the bytes of the binary data
// At this point, you would manually parse the ASN.1 or PKCS#7 structure.
// This involves reading and interpreting headers, tags, and data within the byte array.
// This operation is highly complex and requires a deep understanding of ASN.1 and PKCS#7 formats.
// For example, with ASN.1, you might read bytes, interpret length and field tags, extract data, etc.
// For PKCS#7, you would need to understand the PKCS#7 message structure and read the data accordingly.
// It's important to note that this method requires an in-depth understanding of ASN.1 and PKCS#7 specifications, in addition to being subject to many complexities and potential errors.
但是,这只是一个基本轮廓,实际解码需要更多的手动工作来正确解释 ASN.1 或 PKCS#7 数据的结构,处理定义的长度、标签、序列等。使用 Forge 或 asn1js 等专用库可提供更易于理解和更可靠的 ASN.1 解析功能,从而显着简化此过程。