string - Blowfish encryption Android -


I want to encrypt a string with bluffish in my Android app. The result should be a string because I will send it to my server. I have the following code:

  KeyGenerator keygenerator; Try {keygenerator = KeyGenerator.getInstance ("Blowfish"); Secret Password = Key Creator. Generate (); String key = settings.getString ("key", ""); Byte [] KeyData = Key.getBytes (); Secret KKK = New Securecutis (Keydata, "Blowfish"); Cipher cipher = cipher Get Instances ("Blowfish"); Cipher It (Cipher NCRYPMODEG, KS); Byte [] Encrypted = Cipher .Donfoneal (Message .getBytes ()); Message = new string (encrypted, "UTF-8"); System.out.println ("Encrypt OK"); } Hold (exception e) {System.out.println ("encrypt error"); }   

The problem is that something in the variable message is

R? C? J

But when I decrypt it with javascript (js works fine ...) there is an empty string returned ... (I do not have anything on my website Could not see)

I think the problem is near

  message = new string (encrypted, "UTF-8");   

But how can I solve this problem?

Never use the string as the holder for the byte array Do it.

Either pass directly byte arrays, or use appropriate text of binary data as base 64 or hex.

In your example, you get the string message = new string (encrypted, "UTF-8"), and string message = base 64. encode (encrypted) Some have to change the same code with something. ); (The exact call method description for the chosen base 64 implementation should be correct) Many of the boxes are base 64 implementations.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -