DocuSign对已签名的PDF文档进行哈希处理总是会产生不同的哈希值



我目前正在尝试对一个完整信封的所有文档进行散列。我遇到了一个问题,每当我对GET Document进行REST调用时,它都会返回一个数字唯一的PDF。我已经剥离了PDF的元数据和水印,但无法确定地计算PDF的SHA256哈希。我在下面包含了我的简短代码片段。我想知道DocuSign是否准备了一些独特的头数据,这会改变我PDF的哈希。如有任何协助,我们将不胜感激。我还包含了一个txt文件,该文件记录EOF分隔符的索引,该分隔符表示实际的PDF数据,在每次调用以获取文档时应该是静态的。

让我困惑的是,我能够确定地检索第一个EOF分隔符的索引,该分隔符表示实际PDF的末尾(不包括元数据和水印(。当我继续对切片缓冲区进行散列时,它会继续产生不同的散列值,这让我相信从get document调用返回到DocuSign的第一个0 -> n字节在后续调用中是不同的。

代码:

exports.getDocuments = async (req, res) => {
try {
// Iterate through the list of documents provided and the result of this operation will be a collection [{url: '', data: '', hash: ''}, ...]
let results = await Promise.all(req.body.docs.map(async (currDoc) => {
const config = {headers: {'Authorization': req.body.headers.Authorization}}
// Retrieve Document from DocuSign
let documentResults = await axios.get(currDoc.config.url, config)
// Get the Document Buffer up to the first EOF delimeter
let documentBuffer = await getDocument(documentResults.data, 'binary', currDoc.config.url)
return {
url: currDoc.config.url,
hash: crypto.createHash('sha256').update(documentBuffer).digest('hex') // TODO: Right now always different!!!
}
}))
res.status(200).send(results)
} catch (error) {
console.error(error)
res.status(500).send(error.message)
}
}
function getDocument (data, dataType, url) {
const documentBuffer = Buffer.from(data, dataType)
const documentId = url.split('/').reverse()[0]
const eofBuffer = Buffer.from('n%%EOF', 'ascii')
const documentEofBufferIdx = getAllIndexes(documentBuffer, eofBuffer)
console.log(`DocumentID Buffer first index of id=${documentId}: ${documentEofBufferIdx[0]}`)
console.log('All eof indexes found', documentEofBufferIdx)
// We want to return the document up to the first EOF, EOFs 2 & 3 refer to the metadata and DocuSign watermark.
return Promise.resolve(documentBuffer.slice(0, documentEofBufferIdx[0]))
}
// Iterate through the file and collect all of the EOF indexes.
function getAllIndexes (buf, eofBuf) {
const indexes = []
let i = -1
while ((i = buf.indexOf(eofBuf, i + 1)) !== -1) {
indexes.push(i + eofBuf.length)
}
return indexes
} 

从DocuSign下载文档时,DocuSign在检索文档时对其进行数字签名。使用标准的X.509数字签名。

如果你在Adobe PDF阅读器中打开PDF,它会显示数字信号。签名包括签名的日期时间,这可能是您看到的变化。

如果您了解PDF格式,您可以在没有DocuSign数字签名的情况下从PDF中提取文档。一旦信封达到"完成"状态,这种情况就不会改变。

你的用例是什么?

最新更新