{"id":53982,"date":"2021-09-21T22:47:24","date_gmt":"2021-09-21T17:17:24","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=53982"},"modified":"2024-06-10T15:40:45","modified_gmt":"2024-06-10T10:10:45","slug":"aem-encryption-service-what-how-why","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aem-encryption-service-what-how-why\/","title":{"rendered":"AEM Encryption Service: What, How &#038; Why"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Adobe Experience Manager (AEM) provides an encryption service which helps to encrypt text and decrypt the protected text. The support is available in AEM with the bundle name <\/span><span style=\"font-weight: 400;\"><strong>Adobe Granite Crypto Support<\/strong> (<\/span><i><span style=\"font-weight: 400;\">com.adobe.granite.crypto).<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">It can be used to:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Encrypt properties configured in OSGI configuration service<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Meet the need to protect\/unprotect text or binary data in the backend logic<\/span><\/li>\n<\/ol>\n<h4><b>Protecting OSGI Configuration<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">First the question arises why do we need to protect OSGI configuration when not everyone can access the admin config console?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The answer is simple, OSGI configuration may contain passwords or any sensitive information and at the end when the configuration gets saved, they are saved in the repository and can be accessed from <\/span><i><span style=\"font-weight: 400;\">\/apps<\/span><\/i><span style=\"font-weight: 400;\">. Anyone with access to <\/span><i><span style=\"font-weight: 400;\">\/apps<\/span><\/i><span style=\"font-weight: 400;\"> folder can read them from <\/span><i><span style=\"font-weight: 400;\">crx\/de <\/span><\/i><span style=\"font-weight: 400;\">console. Keeping them in encrypted form helps, as even if the configuration file is accessible from <\/span><i><span style=\"font-weight: 400;\">crx\/de<\/span><\/i><span style=\"font-weight: 400;\">, the property can not be decrypted manually.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In order to protect the OSGI configuration, we need to follow these steps:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">AEM plugins provide a support in felix consoles to decrypt the plain property text, \u201cCrypto support\u201d option is available in under \u201cMain\u201d option in felix console menu or directly access it using url <\/span><i><span style=\"font-weight: 400;\">http:\/\/&lt;host&gt;:&lt;port&gt;\/system\/console\/crypto<\/span><\/i><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54349 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1252\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-scaled.jpg 2560w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-300x147.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-1024x501.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-768x375.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-1536x751.jpg 1536w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-2048x1001.jpg 2048w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-01-624x305.jpg 624w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54350 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-scaled.jpg\" alt=\"\" width=\"2560\" height=\"852\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-scaled.jpg 2560w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-300x100.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-1024x341.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-768x256.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-1536x511.jpg 1536w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-2048x682.jpg 2048w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-02-624x208.jpg 624w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Paste the property value in a plain text field and click on the \u201cProtect\u201d button to get the Protected text<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Use this protected property in any of the OSGI configurations using the configuration manager console or even maintain it in the code base<\/span><\/li>\n<\/ol>\n<h4>Unprotect OSGI Configuration<\/h4>\n<p><span style=\"font-weight: 400;\">There is no need to explicitly decrypt these protected configurations in java configuration service. AEM out of the box (OOTB) returns the properties in java by decrypting them beforehand.<\/span><\/p>\n<h4><b>Protect Plain Text in Java<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">We can use AEM\u2019s crypto API in our backend logic to protect plain text and binary data in backend logics. We need to use <\/span><a href=\"https:\/\/docs.adobe.com\/content\/help\/en\/experience-manager-cloud-service-javadoc\/com\/adobe\/granite\/crypto\/CryptoSupport.html\"><span style=\"font-weight: 400;\">CryptoSupport<\/span><\/a><span style=\"font-weight: 400;\"> Service.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Below is the sample code to protect data:<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-54384\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1252\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-scaled.jpg 2560w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-300x147.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-1024x501.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-768x375.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-1536x751.jpg 1536w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-2048x1001.jpg 2048w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-03-624x305.jpg 624w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/p>\n<h4><b>Unprotect Protected Text in Java<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">We can unprotect protected text and binary data in backend logics using <\/span><a href=\"https:\/\/docs.adobe.com\/content\/help\/en\/experience-manager-cloud-service-javadoc\/com\/adobe\/granite\/crypto\/CryptoSupport.html\"><span style=\"font-weight: 400;\">CryptoSupport<\/span><\/a><span style=\"font-weight: 400;\"> Service.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Below is the sample code to unprotect data:<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-54385\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1252\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-scaled.jpg 2560w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-300x147.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-1024x501.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-768x375.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-1536x751.jpg 1536w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-2048x1001.jpg 2048w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-04-624x305.jpg 624w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/p>\n<h4><b>Using Crypto Support for Multiple Publisher Environment Setup<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">In order to support cryptography in multiple publisher AEM instances setup, we need to have the same HMAC key across all instances. This setup is must if:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">We maintain protected configuration in the code base that is deployed on all publishers.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If text protected in one instance reaches another instance for decryption in backend logic.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If we enable <\/span><a href=\"https:\/\/experienceleague.adobe.com\/docs\/experience-manager-65\/administering\/security\/encapsulated-token.html?lang=en\"><span style=\"font-weight: 400;\">Encapsulated Token Support<\/span><\/a><span style=\"font-weight: 400;\"> in AEM. In this, we will have to sync keys of author instances also with all publisher instances.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">If we do not sync the HMAC keys over all instances, we are going to get <\/span><b>Crypto Exception com.adobe.granite.crypto.CryptoException<\/b><span style=\"font-weight: 400;\"> exception upon decryption.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Steps to sync keys across all instances for <\/span><b>AEM 6.3 or above<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to <\/span><i><span style=\"font-weight: 400;\">\/system\/console\/bundles<\/span><\/i><span style=\"font-weight: 400;\"> and search for a bundle with name \u201c<\/span><a href=\"http:\/\/localhost:4502\/system\/console\/bundles\/20\"><span style=\"font-weight: 400;\">Adobe Granite Crypto Bundle Key Provider\u201d i.e \u201dcom.adobe.granite.crypto.file<\/span><\/a><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u201d and note down the bundle number. In below screenshot, bundle number is 20.<br \/>\n<\/span><\/span><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54351 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-scaled.jpg\" alt=\"\" width=\"2560\" height=\"656\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-scaled.jpg 2560w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-300x77.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-1024x262.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-768x197.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-1536x393.jpg 1536w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-2048x524.jpg 2048w, \/blog\/wp-ttn-blog\/uploads\/2021\/09\/Blog16-05-624x160.jpg 624w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><span style=\"font-weight: 400;\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to repository in filesystem and go to folder <\/span><i><span style=\"font-weight: 400;\">&lt;repository-folder&gt;\/crx-quickstart\/launchpad\/felix\/<\/span><\/i><b><i>bundle20<\/i><\/b><span style=\"font-weight: 400;\"> and here the bundle folder is bundle20 because the number for the <\/span><a href=\"http:\/\/localhost:4502\/system\/console\/bundles\/20\"><span style=\"font-weight: 400;\">com.adobe.granite.crypto.file<\/span><\/a><span style=\"font-weight: 400;\"> is 20 in previous step.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to data folder and copy two files present i.e <\/span><b>hmac<\/b><span style=\"font-weight: 400;\"> and <\/span><b>master<\/b><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Now follow the same steps for all the other instances and replace the two files with copied files.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Once done refresh <\/span><a href=\"http:\/\/localhost:4502\/system\/console\/bundles\/4\"><span style=\"font-weight: 400;\">Adobe Granite Crypto Support bundle i.e <\/span><i><span style=\"font-weight: 400;\">com.adobe.granite.crypto<\/span><\/i><\/a><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Steps to sync keys across all instances for <\/span><b>AEM 6.2 or below:<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create package of path \/etc\/key from one of the instance using package manager<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Install the package created in other instances<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Restart all the instances where package has been installed<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">We hope this article helps you.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Adobe Experience Manager (AEM) provides an encryption service which helps to encrypt text and decrypt the protected text. The support is available in AEM with the bundle name Adobe Granite Crypto Support (com.adobe.granite.crypto). It can be used to: Encrypt properties configured in OSGI configuration service Meet the need to protect\/unprotect text or binary data in [&hellip;]<\/p>\n","protected":false},"author":994,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":374},"categories":[5868,446,1],"tags":[4847,4921,4920],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/53982"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/994"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=53982"}],"version-history":[{"count":7,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/53982\/revisions"}],"predecessor-version":[{"id":54437,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/53982\/revisions\/54437"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=53982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=53982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=53982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}