Monday 29 July 2013

Reading Cookies & Encrypting data

Below is a little bit of code to loop through cookie data.
It also adds a cookie whose data has been encrypted by CQ.  And, decrypts it too.


<%@ include file="/libs/foundation/global.jsp" %><%
%><%@ page contentType="text/html; charset=utf-8"%><%
%><%@ page import="org.apache.commons.lang.StringUtils"%><%
%><%@ page import="javax.servlet.http.Cookie"%><%
%><%@ page import="com.adobe.granite.crypto.CryptoSupport"%><%
%>
<h1>Cookie example</h1>
<%
    CryptoSupport cryptoSupport = sling.getService(com.adobe.granite.crypto.CryptoSupport.class);

    // Create an encrypted string of the data.
    String str1 = cryptoSupport.protect("Helloooo");
    // Base 64 encode the encrypted string so that only permitted Cookie data is stored.
    Cookie ck1 = new Cookie ("testCookie", java.net.URLEncoder.encode(str1));

// Additional protection - only send the cookie over HTTPS
//ck1.setSecure(true);
// Additional protection - do not let JavaScript access this Cookie
//ck1.setHttpOnly(true);

    slingResponse.addCookie(ck1);


// List out all of the Cookies, including decrypting our special Cookie.
    Cookie[] cookies = slingRequest.getCookies();
    if (cookies != null)
    {
        for (Cookie ck : cookies)
        {
            if ("testCookie".equals(ck.getName()))
                {
                %><p> <strong><%= ck.getName() %></strong> == <%= cryptoSupport.unprotect(java.net.URLDecoder.decode(ck.getValue())) %></p><%
                }
                else
                {
    %><p> <%= ck.getName() %> == <%= ck.getValue() %></p><%
                }
        }
    }

%>
<hr/>


17 comments:

  1. One of the biggest challenges that organizations face today is having inaccurate data and being unresponsive to the needs of the Adobe CQ5 CMS Email List organization.

    ReplyDelete
    Replies
    1. Great code, the author is handsome! It seemed to me that you have it too detailed and from this large in size, I think you can reduce it at least twice if you use pseudo-classes and identifiers, for example, I generally recommend watching a video on Instagram on how to shorten any code by almost five times and not cut it its functionality, unfortunately I don't remember the name of this account, but I do remember that it had about 54 thousand of followers! I am sure that the author of this account usualy buy instagram followers in order to quickly gain their amount.

      Delete
    2. My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download Now

      >>>>> Download Full

      My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download LINK

      >>>>> Download Now

      My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download Full

      >>>>> Download LINK BD

      Delete
  2. Thanks Man this is helpful

    ReplyDelete
  3. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training

    ReplyDelete
  4. I study a lot of similar material at university, but sometimes it's hard for me to catch up with all the information I get. Not to mention it's even harder to do assignment writing. So in order to make my education easier I use my favorite professional writing service to get any type of academic paper done on point and with the best quality.

    ReplyDelete
  5. Essays will be unique each time. You might think that you can have a similar experience when you choose to buy custom essays online but how sure are you that those essays have not been used by other people before? information here The chances may be slim but it will still be best to hire a professional writer who will write your paper from scratch. This way, you will not be accused of plagiarizing work.

    ReplyDelete
  6. If you want your clients to recieve the fast answer for their requests, you should better hire the expert services wow24-7.io

    ReplyDelete
  7. I recommend you to check https://celltrackingapps.com/is-there-a-truly-free-reverse-phone-number-lookup/ out if you want to find completely free reverse phone lookup with name. It was really useful for me and my friends

    ReplyDelete
  8. Nice blog with Amazing information .. love to read about this.
    Awaiting for your new post
    We at Fullassignment.com bring to you the most significant Marketing assignment help writing service at the best cost. With long stretches of understanding we are prepared to give assignment help over the globe.You will be guided here with a portion of the information of Marketing assignment which could assist you in deciding writing a Marketing assignment. Nonetheless, we unequivocally prescribe you to benefit Supply chain Management from our specialist to find out about marketing and its scope.We also provide MBA Assignment Help from our experts.

    https://fullassignment.com/

    ReplyDelete
  9. My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download Now

    >>>>> Download Full

    My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download LINK

    >>>>> Download Now

    My Aem (Cq) Blog: Reading Cookies And Encrypting Data >>>>> Download Full

    >>>>> Download LINK G3

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. After we began working with the organisation Studentshare my kid has gotten better at creating lyrics, which is something he likes doing. He just goes to the internet to read, practise, and apply the advice to create exceptional, one-of-a-kind articles. As a consequence, I wholeheartedly endorse this website for learning and inspiration.

    ReplyDelete