My requirement briefly – Signal the ‘Pdf doc’s Hash’ utilizing ‘Digital Signature’ with a .pfx certificates and return the ‘signed hash’ (signed pdf)
1. I’ve 1 pdf in my native patch(in Xcode), and that pdf comprises a ‘rectangular field’ for digital signing
2. Then I’m producing SHA256 Hash from the pdf doc.
- Right here I’m changing pdf into base64 string and utilizing the next perform I’m producing SHA256 Hash
let samplePdfBase64String = "JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8D.....T0YNCg=="
guard let information = samplePdfBase64String.information(utilizing: .utf8) else { return }
let digest = SHA256.hash(information: information)
print(digest.hexStr) // 3DAD8D6CD86B405DCB06FE6E546C8792CE23DCF67B9772E11C14292D32925C7B
let pdfsHashValue = digest.hexStr
I’m utilizing following extension
extension Digest { //It'll gnerate hash worth
var bytes: [UInt8] { Array(makeIterator()) }
var information: Knowledge { Knowledge(bytes) }
var hexStr: String {
bytes.map { String(format: "%02X", $0) }.joined()
}
}
3. Now I must signal the Hash utilizing the pfx file. (Signal Hash utilizing Digital Signing)
From step 2, already I generated hash worth ( pdfsHashValue = "3DAD8D6CD86B405DCB06FE6E546C8792CE23DCF67B9772E11C14292D32925C7B" )
I’ve a legitimate .pfx file and added it into Xcode.
let pfxFile = Bundle.principal.path(forResource: "fred", ofType: "pfx")
4. Now I would like so as to add a signature to this hash (pdf’s hash). A signature can include particulars just like the Title of the signer, location, Purpose..and so on
Utilizing a mix of 1. some hashing algorithms ex. SHA256, 2. pfx certificates and its password, 3. A hash worth (pdf’s hash)
- it ought to course of and return the signed hash (signed pdf’s hash).
- That digital signature ought to pad//append to signed hash
5. remaining output – it ought to return a signed hash (signed pdf)
Briefly,
generate SHA256 hash from pdf file -> Signal the Hash utilizing Digital Certificates -> Pad nack the Signed Hash -> return Signed hash/pdf.
Can somebody assist me to attain this? I attempted Foxit SDK, PSPdfkit library – not helped me as a result of they’re utilizing direct pdf for signing.