Using binary data inside doFinal() - javax.crypto.Cipher
In my project, I xor'ed (sorry but dont know the proper verb) a string and encrypted with RSA-1024. Now I have an xored and encrypted string like:
994624f87a00f4c3066c2a2d38917fe4971be8ad4e6ba58d14cc8b27ab8db84ec2a577f7bda1839cb9843ce6f738f51807ba127b775725ef14e3cea61091bf1fdcfa1372e1975f1b9418b0ad396bea5e7d2a832b8c4161e3b0595f7ed7e57eeda0ad8ab7a7268c871ab4e6d13e3caccaa8b54740ec2d1b8d23d835ff77c78161
When i try to decrypt with...
Cipher cipher2 = Cipher.getInstance("RSA");
c开发者_StackOverflowipher2.init(Cipher.DECRYPT_MODE, priKey);
byte[] cipherData = cipher2.doFinal(data);
it returns non-logical characters like
â—?â—?â—?â—?â—?â—?â—?â—?
i know the reason; when bits that have proper ascii counterparts xored, the answer may not have an ascii counterpart. So im trying to find a different format such as binary to use inside doFinal().
Looking forward to an answer,
Thanks in advance.
Why are you XORing the plaintext? If you're going to encrypt it anyway, XORing doesn't seem to accomplish anything.
Beyond that cipherData
is a misleading name: that's actually your (XORd) cleartext, since you are getting it from the decryption step.
If you continue with the XOR scheme, you need to XOR those bytes again before attempting to decode them into a String. When you do that step, you probably need to specify the encoding used, e.g., UTF-8, just to be safe.
精彩评论