Refresh . It seems that the problem occurs before passing data to forge. Data is not read in the appropriate format. You can try one of these options:
Option 1:
reader.readAsDataURL(p12cert); // change from readAsText // in reader.onload, parse out the base64 part: var p12Der = forge.util.decode64(eve.target.result.split(',')[1]);
Option 2:
reader.readAsBinaryString(p12cert); // change from readAsText // in reader.onload, skip base64 decoding step entirely since the data is // already in a binary string that forge can work with
Option 3:
// instead, use an ArrayBuffer reader.readAsArrayBuffer(p12cert); // in reader.onload, convert to base64 and then decode as you were doing before var b64 = forge.util.binary.base64.encode(new Uint8Array(eve.target.result));
Option 4:
// instead, use an ArrayBuffer reader.readAsArrayBuffer(p12cert); // in reader.onload, just do a raw conversion to a binary string and skip // the base64 decoding (though this may cause a stack overflow // with the current implementation in forge which is experimental) var p12Der = forge.util.binary.raw.encode(new Uint8Array(eve.target.result));
Old
Have you tried loading PKCS # 12 in non-strict mode? This often fixes this error:
var p12Asn1 = forge.asn1.fromDer(p12Der, false); var p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, false, password);
dlongley
source share