April 27, 2020
Estimated Post Reading Time ~

Encrypting/Decrypting data in AEM

com.adobe.granite.crypto.CryptoSupport service can be used to encrypt/decrypt the data in Adobe Experience Manager(AEM).

Maven Dependency:

<dependency>
<groupId>com.adobe.granite</groupId>
<artifactId>com.adobe.granite.crypto</artifactId>
<version>0.0.18</version>
<scope>provided</scope>
</dependency>

Service to encrypt/decrypt the message:

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;

@Component(immediate = true, metatype = true)
@Service(value = EncrypionService.class)
public class EncrypionService {
@Reference
private CryptoSupport cryptoSupport;

public String encrypt(String plainText) throws Exception

{
try {
return cryptoSupport.protect(plainText);
} catch (CryptoException e) {
throw e;
}
}

public String decrypt(String encryptedText) throws Exception
{
try {
return cryptoSupport.unprotect(encryptedText);
} catch (CryptoException e) {
throw e;
}
}
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.