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

Getting a pad block corrupted error #19

Open
Prasadnair opened this issue Oct 4, 2023 · 8 comments
Open

Getting a pad block corrupted error #19

Prasadnair opened this issue Oct 4, 2023 · 8 comments

Comments

@Prasadnair
Copy link

Hello @claboran,

I'm facing an issue while validating the private key and passphrase. Please advise what would be the root cause of the error "pad block corrupted"

at Org.BouncyCastle.Crypto.Paddings.Pkcs7Padding.PadCount(Byte[] input)
at Org.BouncyCastle.Crypto.Paddings.PaddedBufferedBlockCipher.DoFinal(Byte[] output, Int32 outOff)
at Org.BouncyCastle.Crypto.BufferedBlockCipher.DoFinal(Byte[] input, Int32 inOff, Int32 inLen)
at Org.BouncyCastle.OpenSsl.PemUtilities.Crypt(Boolean encrypt, Byte[] bytes, Char[] password, String dekAlgName, Byte[] iv)
at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)
at Org.BouncyCastle.OpenSsl.PemReader.ReadObject()
at ForceDotNetJwtCompanion.Util.KeyHelpers.CreatePrivateKeyWrapperWithPassPhrase(String key, String passphrase)
at ForceDotNetJwtCompanion.JwtAuthenticationClient.d__29.MoveNext().

Note:
we are renewing our certificate.

@claboran
Copy link
Owner

claboran commented Oct 5, 2023

@Prasadnair: How did you generate the key? Would be good to have the version too.

@claboran
Copy link
Owner

claboran commented Oct 5, 2023

@Prasadnair Did you have the --traditional flag added?
openssl genrsa -des3 -traditional -passout pass:secret -out server-new.pass.key 2048

@Prasadnair
Copy link
Author

Prasadnair commented Oct 5, 2023

we are using external certificate. I upload the public key and validated using the private key.

private key below
-----BEGIN PRIVATE KEY-----

-----END PRIVATE KEY-----

@Prasadnair
Copy link
Author

got another issue when tried with another private which I received form the platform team.
System.InvalidCastException: 'Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair

any insights on this?

@Prasadnair
Copy link
Author

Pad block corrupted error again
at Org.BouncyCastle.Crypto.Paddings.Pkcs7Padding.PadCount(Byte[] input)
at Org.BouncyCastle.Crypto.Paddings.PaddedBufferedBlockCipher.DoFinal(Byte[] output, Int32 outOff)
at Org.BouncyCastle.Crypto.BufferedBlockCipher.DoFinal(Byte[] input, Int32 inOff, Int32 inLen)
at Org.BouncyCastle.OpenSsl.PemUtilities.Crypt(Boolean encrypt, Byte[] bytes, Char[] password, String dekAlgName, Byte[] iv)
at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)
at Org.BouncyCastle.OpenSsl.PemReader.ReadObject()
at ForceDotNetJwtCompanion.Util.KeyHelpers.CreatePrivateKeyWrapperWithPassPhrase(String key, String passphrase)
at ForceDotNetJwtCompanion.JwtAuthenticationClient.d__29.MoveNext()

@Prasadnair
Copy link
Author

Prasadnair commented Oct 5, 2023

Final Update:
I followed the below steps

Generate a private key, and store it in a file called server.key
openssl genrsa -des3 -passout pass:secret -out C:\CT\SFCert\server.pass.key 2048
openssl rsa -passin pass:secret -in C:\CT\SFCert\server.pass.key -out C:\CT\SFCert\server.key
Generate a certificate signing request using the server.key file. Store the certificate signing request in a file called server.csr. Enter information about your company when prompted.
openssl req -new -key C:\CT\SFCert\server.key -out C:\FCT\SFCert\server.csr
Generate a self-signed digital certificate from the server.key and server.csr files. Store the certificate in a file called server.crt
openssl x509 -req -sha256 -days 500 -in C:\CT\SFCert\server.csr -signkey C:\CT\SFCert\server.key -out C:\CT\SFCert\server.crt

now I'm getting this error:
System.InvalidCastException: 'Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.'

@Prasadnair
Copy link
Author

I created the crt using OpenSSL 1.1 with 32 bit. it got success.

how this can be achieved using OpenSSL 3.0 Please advise

@claboran
Copy link
Owner

claboran commented Oct 7, 2023

@Prasadnair I need to check how I can get this to work for OpenSSL 3. I know that this is an long term issue.

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