Вопрос

I am working on a problem where client is sending email thru URL in encrypted format. We have to use blowfish for encryption at Client end and decryption at out end.

BLOWFISH CODE below---

//ENCRYPTED  as  jAOtTv22BfkTkVrhTN/RHQ==   
public String encrypt(String username,String code) throws Exception {
     try {
    byte[] keyData = (username).getBytes();
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, "Blowfish");
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
    byte[] hasil1 = cipher.doFinal(username.getBytes());
byte[] hasil2 = cipher.doFinal(code.getBytes());
return new BASE64Encoder().encode(hasil1);
    } catch (Exception e) { System.out.println(e);
    return null; }
}

//DECRYPT  --doug@gmail.com
public String decrypt(String email,String code) throws Exception {
    try {
    byte[] keyData = (code).getBytes();
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, "Blowfish");
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    byte[] hasil = cipher.doFinal(new BASE64Decoder().decodeBuffer(email));
    return new String(hasil);
    } catch (Exception e) {  System.out.println("exaception ="+e);
    return null; }
}

We need to decrypt and mask before showing on web page. But the problem with special character coding coming as url. how to handle it for decrypting at our side??? for example we are getting this -

  http://localhost/demo/Controller?email=jAOtTv22BfkTkVrhTN/RHQ%3D%3D

where blowfish encryption is - jAOtTv22BfkTkVrhTN/RHQ==

Works fine where no special character code involved

e.g - wK6DTqKguftd0%2BePXqlB9BORWuFM39Ed

Character code in url ---

 http://perishablepress.com/url-character-codes/

thanks for any suggestion or help in advance.

Это было полезно?

Решение

If you understand you right, you have problems with URL specific character masking like "=".

If this is so, you can use

java.net.URLDecoder.decode(text, encoding)

to decode the base64 string.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top