0

I have the following encoding in the javascript file:

var words = CryptoJS.enc.Utf8.parse("cy03ISBnqOMGQZoAvpAszw=="); 

and it gives me out put as - (I have checked it on http://jsfiddle.net/9Hyfd/)

result: 637930334953426e714f4d47515a6f41767041737a773d3d 

If I try to write the same thing in JAVA it gives me output as:

[99, 121, 48, 51, 73, 83, 66, 110, 113, 79, 77, 71, 81, 90, 111, 65, 118, 112, 65, 115, 122, 119, 61, 61]

Here is the code:

import java.util.*;
import java.lang.*;
import java.io.*;

class convertsample
{
    public static void main (String[] args)
    {

    String a = "cy03ISBnqOMGQZoAvpAszw==";
    byte[] u = a.getBytes("UTF-8");   
        //System.out.println(u); 
        System.out.println(Arrays.toString(u));
       // String s = new String(u, "US-ASCII");
        //System.out.println(s); 
    }
}

What is wrong with the java code?

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
Ora Aff
  • 640
  • 1
  • 9
  • 24
  • You are using Arrays.toString(), it gives a representation of the byte array (for example the first character c is in fact encoded as 99 in ASCII and hence UTF-8), see [this question](http://stackoverflow.com/questions/5673059/converting-byte-array-to-string-java) about converting a byte array to a string – Jacopofar Dec 10 '13 at 09:56
  • Thanks Bosko. Got the java working now. – Ora Aff Dec 10 '13 at 10:13

0 Answers0