0
public String encrypt(String line) throws UnsupportedEncodingException {

    String newLine = "";

    byte[] bytes = line.getBytes("UTF-8");
    for (byte c : bytes) {
        newLine += Integer.toHexString(c);
    }
    System.out.println(newLine);

    return newLine;
}

public String decrypt(String line) throws UnsupportedEncodingException {

    String newLine = "";

    byte[] bytes = line.getBytes("UTF-8");
    for (byte b : bytes) {
        char c = (char) b;
        newLine += c;

    }

    return newLine;
}

These are the two methods. don't know how to correct this. so can make it correct and how? I want covert the returned line of encrypt to normal line in decrypt method

lokusking
  • 7,396
  • 13
  • 38
  • 57
  • First method converts UTF-8 string to HEX and second one HEX string to UTF-8. What's your problem? – Blady214 Nov 08 '16 at 07:58
  • It is a simple encrypt and decrypt class. these two methods return same output. I want to convert encrypted line again to what I input before from decrypt method – sandamal wijeweera Nov 08 '16 at 08:01
  • @Blady214 The problem is that the second method doesn't do what you say. The first method converts one char into two chars representing one byte. The second method takes one byte and converts it to one char where it should take two bytes and convert them to one char. – Thorsten Dittmar Nov 08 '16 at 08:02
  • Yes . I dont understand how to do it – sandamal wijeweera Nov 08 '16 at 08:03
  • @sandamalwijeweera Please stop calling this encryption. This is not encryption and in case you think that this adds any level of security, please stop doing what you're doing and read up on security/encryption. – Thorsten Dittmar Nov 08 '16 at 08:03
  • @sandamalwijeweera Read the answers to this question: http://stackoverflow.com/questions/4785654/convert-a-string-of-hex-into-ascii-in-java – Thorsten Dittmar Nov 08 '16 at 08:04
  • this is a simple to hide data in a text. we dont have a chance to use any algorithms like MD5 and AES.. So I created this one – sandamal wijeweera Nov 08 '16 at 08:05
  • @sandamalwijeweera MD5 is not about encryption, it is a hash algorithm. If you want to use that code to "hide" something you can just the same write plain text, as this code provides exactly 0% security and it takes 0% effort to decode it. You could **at least** have tried to implement some sort of ROT encryption to show a minimum amount of knowledge in the field. – Thorsten Dittmar Nov 08 '16 at 08:50

0 Answers0