Skip to content

Commit c5c5b94

Browse files
Merge pull request #5 from angel-one/KYCNEW-19246
password protected pdf decryption issue
2 parents 436375b + ed077b7 commit c5c5b94

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/pdfcpu/crypto.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,21 @@ func validateOwnerPassword(ctx *model.Context) (ok bool, err error) {
739739

740740
func validateCFLength(len int, cfm *string) bool {
741741
// See table 25 Length
742+
// Note: Length can be expressed in bytes or bits depending on the security handler.
743+
// AESV2 (AES-128) expects Length=16 (bytes) or Length=128 (bits)
744+
// AESV3 (AES-256) expects Length=32 (bytes) or Length=256 (bits)
742745

743746
if cfm != nil {
744-
if (*cfm == "AESV2" && len != 16) || (*cfm == "AESV3" && len != 32) {
747+
if *cfm == "AESV2" && len != 16 && len != 128 {
745748
return false
746749
}
750+
if *cfm == "AESV3" && len != 32 && len != 256 {
751+
return false
752+
}
753+
// If we matched a valid AESV2 or AESV3 length, return early
754+
if *cfm == "AESV2" || *cfm == "AESV3" {
755+
return true
756+
}
747757
}
748758

749759
// Standard security handler expresses in bytes.

0 commit comments

Comments
 (0)