Jump to content

mehulkatara

Members
  • Posts

    11
  • Joined

  • Last visited

mehulkatara's Achievements

Rookie

Rookie (2/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  2. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  3. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  4. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  5. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  6. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  7. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  8. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  9. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  10. Follow this link for Jasper Token Based Authentication https://github.com/mehulkatara/Jasper-Token-based-Authentication
  11. I have implemented token-based authentication with base64 encryption method. It's working but sometimes when I pass token it reject that token because of below error Error while decrypting !java.lang.IllegalArgumentException: Illegal base64 character 20Error while descrypt GetMEssage() : Illegal base64 character 20[/code]Hear the example of token Token Pass: u=Katara Mehul Token Fail: u=Mehul Katara below is my java encryption mechanism package com.jaspersoft.cipher;import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.util.Arrays;import java.util.Base64;import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;import com.jaspersoft.jasperserver.api.common.crypto.CipherI;public class myCipher implements CipherI{ private SecretKeySpec secretKey; private byte[] key; String myKey="123"; public void setKey(String myKey) { MessageDigest sha = null; try { key = myKey.getBytes("UTF-8"); sha = MessageDigest.getInstance("SHA-1"); key = sha.digest(key); key = Arrays.copyOf(key, 16); secretKey = new SecretKeySpec(key, "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } public String decrypt(String strToDecrypt) { try { String secret=myKey; setKey(secret); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, secretKey); return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt.getBytes("UTF-8")))); } catch(Exception e) { System.out.println("Error while decrypting !" +e.toString()); System.out.println("Error while descrypt GetMEssage() : " +e.getMessage()); e.printStackTrace(); } return null; } public String encrypt(String strToEncrypt) { try { String secret=myKey; setKey(secret); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8"))); } catch(Exception e) { System.out.println("Error while encrypting" +e.toString()); } return null; } public static void main(String args[]) { String orginalString="u=Katara Mehul"; myCipher obj = new myCipher(); String encryptString = obj.encrypt(orginalString); String decryptString = obj.decrypt(encryptString); System.out.println(orginalString); System.out.println(encryptString); System.out.println(decryptString); }}[/code]
×
×
  • Create New...