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

jncryptor.InvalidHMACException: Incorrect HMAC value. #30

Closed
maplesnow-zsm opened this issue Nov 2, 2015 · 3 comments
Closed

jncryptor.InvalidHMACException: Incorrect HMAC value. #30

maplesnow-zsm opened this issue Nov 2, 2015 · 3 comments

Comments

@maplesnow-zsm
Copy link

this is the problem about "jncryptor.InvalidHMACException" in android, when i use gson and Base64.decode before the decrypt:

Gson gson = new Gson();
AES256JNCryptor aes256JNCryptor = new AES256JNCryptor();
String string = gson.toJson(data);
byte[] bytes = Base64.decode(string, 0);

then it throw the exception:

com.ilikelabsapp.MeiFu.frame.utils.jncryptor.InvalidHMACException: Incorrect HMAC value.
com.ilikelabsapp.MeiFu.frame.utils.jncryptor.AES256JNCryptor.decryptV3Data(AES256JNCryptor.java:248)
com.ilikelabsapp.MeiFu.frame.utils.jncryptor.AES256JNCryptor.decryptData(AES256JNCryptor.java:280)
com.ilikelabsapp.MeiFu.frame.entity.EncryptNetworkResponse.getData(EncryptNetworkResponse.java:55)

if only i don't use the base64.decode, then it will throw the exception:

jncryptor.CryptorException: Unrecognised version number: 34.
com.ilikelabsapp.MeiFu.frame.utils.jncryptor.AES256JNCryptor.decryptData(AES256JNCryptor.java:283)
com.ilikelabsapp.MeiFu.frame.entity.EncryptNetworkResponse.getData(EncryptNetworkResponse.java:56)

i don't kow how to slove the InvalidHMACException, did i do anything wrong?
Thank you~

@rnapier
Copy link
Member

rnapier commented Nov 2, 2015

Invalid hmac means either your data is corrupted or you have the wrong password. The input must be precisely (byte for byte) the output of the encryptor.

@maplesnow-zsm
Copy link
Author

yes, i find the reason,it's caused by gson, it filtered the escape character like " / " and " ' " and so on,so the data is corrupted,i use "Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();" to solve the issue.

Thank you for the support,there is still another problem,it's too slow in android, it takes me about 3.2s to decrypt,so i'm afraid of i can't use it, hope it can be solved soon~

Thanks again for the cool code~

@dmjones
Copy link
Contributor

dmjones commented May 25, 2016

Main issue is solved. Performance problem is duplicate of #23

@dmjones dmjones closed this as completed May 25, 2016
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