Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKCS#5 / PKCS#7 #7

Open
anniew86 opened this issue Mar 28, 2022 · 1 comment
Open

PKCS#5 / PKCS#7 #7

anniew86 opened this issue Mar 28, 2022 · 1 comment

Comments

@anniew86
Copy link

the About statment mentions PKCS#5 but the coding use PKCS#7 , to get the PKCS#5 following code of DESEncryptor.php have to be removed:

if (!$this->encrypt) {
$aPadding = array_values(unpack('C', substr($text, -1)));
$padding = $aPadding[0];
$text = substr($text, 0, strlen($text) - $padding);
}

I needed to use it with PKCS#5, perhaps you can implement a suitable parameter

@kevinsandow
Copy link
Owner

PKCS#5 is a subset of PKCS#7, where PKCS#7 supports variable block sizes.
In this case the implementation is hard-coded to protected $blockSize = 8; thus using PKCS#5.

The code you mentioned only affects the decryption, are you sure the data was correctly encrypted, since PKCS#5 uses the same decryption method as PKCS#7, quoted from the RFC https://datatracker.ietf.org/doc/html/rfc2898#section-6.1.2

      5. Separate the encoded message EM into a message M and a padding
         string PS:

                 EM = M || PS ,

         where the padding string PS consists of some number psLen
         octets each with value psLen, where psLen is between 1 and 8.
         If it is not possible to separate the encoded message EM in
         this manner, output "decryption error" and stop.

I might not have the last part implemented, to respect only paddings in range from 1 to 8, but otherwise it is implemented as specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants