{"id":4915,"date":"2018-03-16T16:51:00","date_gmt":"2018-03-16T11:21:00","guid":{"rendered":"\/?p=4915"},"modified":"2020-02-04T13:22:59","modified_gmt":"2020-02-04T07:52:59","slug":"crypto-support-aem","status":"publish","type":"post","link":"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/","title":{"rendered":"Crypto Support in AEM: Encrypting Plain Text and Decrypting Protected Text"},"content":{"rendered":"

Recently, we came across a business requirement where we had to save API keys (secured date) in OSGI service. One of the recommendations based on Adobe Health Check is to encrypt data (API keys) to store them in JCR more securely. The same can be achieved using Crypto Support in AEM.<\/p>\n

The Crypto Support Bundle provides a service which encrypts\/decrypts binary or String data in AEM. On exploring further, it seems to be nailing the issue of encryption and decryption in just a few minutes. Crypto support is necessary to store the password in a salted or hashed form in the JCR so as to make the password storage secure and to avoid any breach.<\/p>\n

The following steps will elaborate the mechanism to generate an encrypted key.<\/p>\n

Step 1: Protecting the Plain Text<\/strong><\/h5>\n

Crypto Support bundle provides a service that allows users to generate the \u201cProtected Text\u201d from the \u201cPlain Text\u201d input.<\/p>\n

Open the URL <\/strong>http:\/\/<host>:<port>\/<system\/console\/crypto><\/span><\/p>\n

\"\"
\nIn the \u201cPlain Text\u201d field, add the string which needs to be encrypted and press the protect button. \u201cProtected Text\u201d field will show the encrypted string to be used. plain text string The encryption algorithm used in this procedure is symmetric key encryption namely AES algorithm, CBC mode with PKCS5 padding used from RSA JSafe library.<\/p>\n

For instance, while setting up the SMTP configurations, it is not ideal to keep the password as a plain text in the OSGI config. Best way to do is to encrypt the password using Crypto Support and then use the Protected Text in the SMTP Configurations.<\/p>\n

Next step is to decrypt the protected text in the backend code so as to fetch the original password, which is easy.<\/p>\n

Step 2: Decrypt the Protected Text.<\/strong><\/h5>\n

Since the OSGI configuration has the \u201cProtected Text\u201d configured, it is required to decrypt the value before actually using it.<\/p>\n

Following code sample is used to decrypt the password:<\/p>\n

@Reference\r\nprivate CryptoSupport cryptoSupport;\r\n\r\nprivate void setEmailConfiguration(Object smtpHost,Object smtpPort,Object smtpUser,Object smtpPwd,Object from Address){\r\n\r\n        String password=PropertiesUtil.toString(smtpPwd,StringUtil.EMPTY);\r\n        if(this.cryptoSupport.isProtected(password)){\r\n            this.smtpPassword=this.cryptoSuport.unProtect(password);\r\n            } else {\r\n            this.smtpPassword=password;\r\n            }\r\n        }<\/pre>\n

The method unprotect(String cipherText)<\/em> unprotects (decrypts) the string to return the plain text. We can also check if the String is already protected by using isProtected(String text)<\/em>method. This method returns true if String provided is protected.<\/p>\n

Note that we are not done yet. The protected string generated by Crypto Support will be different for different instances. One last step is required to make sure same protected text can be used throughout. It is an optional step, if different protected strings need to be used on different instances.<\/p>\n

Step 3 (Optional): To Make the Protected Text Same for all the AEM Instances.<\/strong><\/h5>\n

If we intend to use the same protected text for all the environments (it is recommended to use different password for production environment to ensure data integrity), then we need to follow below steps.<\/p>\n

    \n
  1. Download the hmac and master files from the \/etc\/key current instance. The encryption uses a key which is created with AEM installation in OS filesystem under crx-quickstart. These are binary files which are randomly generated at start of Adobe Granite Crypto Support bundle.\n

    \"\"<\/li>\n

  2. Create the \/etc\/key node for the destination instance and copy the above two files.<\/li>\n
  3. Deploy the code and make sure to restart “com.adobe.granite.crypto” for very first time you upload these key and make cryptography effective.<\/li>\n<\/ol>\n

    Note:<\/strong> If we manually stop the Crypto Support bundle, then AEM login fails and the user will be unable to login with any user. Hence, it is always recommended to use CURL command at root directory of the server with admin user only to restart the crypto support bundle.<\/p>\n

    CURL command to stop the bundle:
    \ncurl -u admin:admin
    \nhttp:\/\/<host>:<port>\/system\/console\/bundles\/com.adobe.granite.crypto -F action=stop<\/span><\/p>\n

    CURL command to start the bundle:
    \ncurl -u admin:admin
    \nhttp:\/\/<host>:<port>\/system\/console\/bundles\/com.adobe.granite.crypto -F action=start<\/span><\/p>\n

    Hope this helps you all to smoothly implement encryption\/decryption of the passwords!<\/p>\n

    We have tested this on AEM 6.2<\/p>\n","protected":false},"excerpt":{"rendered":"

    Recently, we came across a business requirement where we had to save API keys (secured date) in OSGI service. One of the recommendations based on Adobe Health Check is to encrypt data (API keys) to store them in JCR more securely. The same can be achieved using Crypto Support in AEM. The Crypto Support Bundle … Read more<\/a><\/p>\n","protected":false},"author":14,"featured_media":6952,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","content-type":"","footnotes":""},"categories":[66],"tags":[81,65,25,82,83,84,41,85,27,86,87,90],"yst_prominent_words":[1095,1107,1090,1089,1093,1102,1099,1105,1096,1094,1101,1091,1104,1106,1108,1097,1098,1092,1100,1103],"acf":[],"yoast_head":"\nCrypto Support in AEM | Encrypting Plain Text, Decrypting Protective Text<\/title>\n<meta name=\"description\" content=\"Crypto Support in AEM enables the secure storage of sensitive data. Encrypt plain text data as protected text and decrypt again through this service.\" \/>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Crypto Support in AEM | Encrypting Plain Text, Decrypting Protective Text\" \/>\n<meta property=\"og:description\" content=\"Crypto Support in AEM enables the secure storage of sensitive data. Encrypt plain text data as protected text and decrypt again through this service.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/\" \/>\n<meta property=\"og:site_name\" content=\"Argil DX\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-16T11:21:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-04T07:52:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.argildx.us\/wp-content\/uploads\/2018\/03\/Crypto-Support-in-AEM-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1440\" \/>\n\t<meta property=\"og:image:height\" content=\"542\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.argildx.us\/#website\",\"url\":\"https:\/\/www.argildx.us\/\",\"name\":\"Argil DX\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.argildx.us\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.argildx.us\/wp-content\/uploads\/2018\/03\/Crypto-Support-in-AEM-1.jpg\",\"width\":1440,\"height\":542,\"caption\":\"Crypto Support in AEM\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/#webpage\",\"url\":\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/\",\"name\":\"Crypto Support in AEM | Encrypting Plain Text, Decrypting Protective Text\",\"isPartOf\":{\"@id\":\"https:\/\/www.argildx.us\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/#primaryimage\"},\"datePublished\":\"2018-03-16T11:21:00+00:00\",\"dateModified\":\"2020-02-04T07:52:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.argildx.us\/#\/schema\/person\/524eee001e21fc23e5cb1679cb76de26\"},\"description\":\"Crypto Support in AEM enables the secure storage of sensitive data. Encrypt plain text data as protected text and decrypt again through this service.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.argildx.us\/technology\/crypto-support-aem\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.argildx.us\/#\/schema\/person\/524eee001e21fc23e5cb1679cb76de26\",\"name\":\"Pankaj Bansal\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.argildx.us\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/500ad1a25df6b77806f6532b458ac144?s=96&d=mm&r=g\",\"caption\":\"Pankaj Bansal\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts\/4915"}],"collection":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/comments?post=4915"}],"version-history":[{"count":0,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts\/4915\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/media\/6952"}],"wp:attachment":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/media?parent=4915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/categories?post=4915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/tags?post=4915"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/yst_prominent_words?post=4915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}