Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper server using the encrypted token in javascript


showmethemoney2488

Recommended Posts

I have emplemented an token-based encryption with Jasper server. My question is how will I used this in my javascript to especially in iframe?

http://localhost:8080/jasperserver?pp=l4O3_onTsKh_vsBmfios-u72esQMepeawMD3QQkOE_ETDX1dvb3af4o5h4dXjpFyUOA2J5XrYSzreQ==

Above is the encrypted token.

Here's my java code which I compiled to .jar then added in WEB-INF/lib folder.

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 NewClass implements CipherI{    private SecretKeySpec secretKey;    private byte[] key;    String myKey="Mehul Katara";     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, "RC4");            }            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("RC4");            cipher.init(Cipher.DECRYPT_MODE, secretKey);            return new String(cipher.doFinal(Base64.getUrlDecoder().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("RC4");            cipher.init(Cipher.ENCRYPT_MODE, secretKey);            return Base64.getUrlEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));        }        catch(Exception e)        {            System.out.println("Error while encrypting"  +e.toString());        }        return null;    }}

I also modified the xml

  <property name="tokenDecryptor">        <!--<bean class="com.jaspersoft.jasperserver.api.common.crypto.DevelopmentPlainTextNonCipher"/>-->        <bean class="com.jaspersoft.cipher.NewClass"/>    </property>

I'm very confused right now on how to login using the token. If I go directly to the link above it will just send me to login page. The documentation is not very detailed about it.

Link to comment
Share on other sites

  • 1 year later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...