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

Hash mismatch #578

Open
lixianbin1 opened this issue Mar 28, 2023 · 6 comments
Open

Hash mismatch #578

lixianbin1 opened this issue Mar 28, 2023 · 6 comments

Comments

@lixianbin1
Copy link

lixianbin1 commented Mar 28, 2023

The Java personnel used RSA/EBC/OAEPWithSHA-256AndMGF1Padding for encryption, but when I got this, I couldn't solve it, prompting me to Hash mismatch. Can anyone point out my problem? Here is my code

const key =`-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCUjrVC/XhTC+or
l4qe6IcH7rKDnZhxwInROTzkYaqWyYjU543ObEnnEB93kGxrP6oEGR4LRzWNsPsX
WLsCTqdVWw14r++EahFq2odjlvztDGP24csO0Sw5QFbbVe4V7wuIOIW9WLZDfb3K
Krd3K0VgNAEtGu3Um+OqFXJOsABHjCwePB7GCeDcZ3DHkc3/juwnUOlPCkeL3qTi
DZKQwAPPGMgi7+3p5mCAe670EqcOFLlJNHW77uYEOixTQFC/ZgMg95mJ3eRfrzv7
DBQZ6LJbKcHXz/7XWnsSSZ7sAKBS58AxJCH/2QEAkZfocFdsOPDSEXBe2D1Du5Io
Mm6lFCDfAgMBAAECggEAEzvKwgqZGn9vaQdsvhgy61b/K8UqqIeaEEmN1a/Da1Ra
b94u4OvqQY031b4QG26Zr4AlAKbOizK/v40QYUMXrRhlzRtSMl2dNa1nXAB/bJ1v
D9a5+IgiZqMq26jrc1GIt7FBt3sV1fUgrl0LddVXXRY+lL1oz18DgdDXBNMKpjiQ
Olz8aPz9fviagWaXyUXfqMgyGE1rdC1+u1hU1dSLa5fPegR78Me9lDtpKIvljYd4
Hl8J6hmPK39HV5dfNXVE29di9Ndx5l4DEMb545cgIMNISFdu81u5MX+Dh/Dk1zKT
JM/8B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VkylpAoXCLRVBzeMoPVDN5HYrePPQjisoPaEMY7hram4n+w4LEmVatOLzmdKvEnGcqUC7cpuT6lc1uqqcVrQgnSA9VdOBhc7g9LZKGSvfJwFimX/dODdnAym//hAliH8KuNjPGJZmlJ7TtIxx0FnSqAvIMBYJbghSsDkAKG8kpNUd17yMeBWYoNtXPkUOwtZZ2fsyr1Tss7oJoycRxbb/8Ow==`
var prvKey = jsrsasign.KEYUTIL.getKey(key);
var decJava = jsrsasign.KJUR.crypto.Cipher.decrypt(jsrsasign.b64utohex(text), prvKey,'RSAOAEP256');
@lixianbin1
Copy link
Author

This is my decryption through the online website, which can be successful
企业微信截图_16799772913150

@xezzon
Copy link

xezzon commented Jun 30, 2023

Please try to encode the content to be encrypted as Base64 or Hex.

@xezzon
Copy link

xezzon commented Jun 30, 2023

It seems that this problem occurs when the plaintext is too long.

@kjur
Copy link
Owner

kjur commented Jun 30, 2023

It seems that this problem occurs when the plaintext is too long.

Message shall be smaller than your key size.

@xezzon
Copy link

xezzon commented Jul 1, 2023

Whether segmented decryption is supported or will be supported soon?

@kjur
Copy link
Owner

kjur commented Jul 1, 2023

Whether segmented decryption is supported or will be supported soon?

There is no plan to support it because openssl pkeyutl encryption doesn't support it too.

cat largefile.zip | openssl pkeyutl -encrypt -pubin -inkey a.pub > encrypted.dat
Public Key operation error
80C5A90001000000:error:0200006E:rsa routines:
ossl_rsa_padding_add_PKCS1_type_2_ex:data too large for key size:crypto/rsa/rsa_pk1.c:129:

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

3 participants