如何使用Javascript解码PKCS#7/ASN.1?

问题描述 投票:0回答:1

最近我开始从事 Apple 应用商店收据验证工作,由于旧版

/verifyReceipt
端点已弃用,我决定采用 设备上验证。所描述的指南给出了
MacOS
的分步解决方案,但是我们希望使用 NodeJs 在后端服务中执行此验证。为此,需要对
PCKS7#
容器中定义的信息进行解码。在这里,我的知识很短,因为我无法检索这些信息(例如
receipt_creation_data
bundle_id
)我设法将收据从
PCKS7
转换为
ASN.1
,但找不到从中检索实际键值的方法它。我尝试了几个库,例如
node-forge
asn1js
asn1.js
。我发现真正有用的是这些资源:

AFAIK 信息应以 OCTET STRING 格式编码

如何使用 Javascript 从 ASN.1 检索诸如

bundle_id
receipt_creation_date
之类的信息?

javascript app-store asn.1 pkcs#7
1个回答
0
投票

// 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 解析功能,从而显着简化此过程。

© www.soinside.com 2019 - 2024. All rights reserved.