Appendix
Encrypt.xsl
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:dpconfig="http://www.datapower.com/param/config"
xmlns:apim="http://www.ibm.com/apimanagement"
xmlns:webapi="http://www.ibm.com/apimanagement"
xmlns:func="http://exslt.org/functions"
xmlns:wxsl="http://www.w3.org/1999/XSL/TransformAlias"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="dp dpconfig exsl apim"
exclude-result-prefixes="wxsl func dp">
<xsl:template match="/">
<xsl:variable name="vAlgorithm" select="'http://www.w3.org/2001/04/xmlenc#aes256-cbc'"/>
<xsl:variable name="vPlainText" select="//*[local-name()='ClearText']"/>
<xsl:variable name="vKey" select="'name:EncryptDecryptKey'"/>
<!-- The console log for the text and key are commented out to ensure the logs will not capture the plain text or key, but you may uncomment for debugging. -->
<!-- <xsl:message>****PlainText: <xsl:value-of select="$vPlainText"/>
</xsl:message>
<xsl:message>****Key: <xsl:value-of select="$vKey"/>
</xsl:message> -->
<xsl:message>****Algorithm: <xsl:value-of select="$vAlgorithm"/>
</xsl:message>
<xsl:variable name="vCipherString">
<xsl:value-of select="dp:encrypt-string($vAlgorithm,$vKey,$vPlainText)"/>
</xsl:variable>
<encryptResponse>
<encryptedText>
<xsl:value-of select="$vCipherString"/>
</encryptedText>
</encryptResponse>
</xsl:template>
</xsl:stylesheet>
Decrypt.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:dpconfig="http://www.datapower.com/param/config"
xmlns:apim="http://www.ibm.com/apimanagement"
xmlns:webapi="http://www.ibm.com/apimanagement"
xmlns:func="http://exslt.org/functions"
xmlns:wxsl="http://www.w3.org/1999/XSL/TransformAlias"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="dp dpconfig exsl apim"
exclude-result-prefixes="wxsl func dp">
<xsl:template match="/">
<xsl:variable name="vAlgorithm" select="'http://www.w3.org/2001/04/xmlenc#aes256-cbc'"/>
<xsl:variable name="vKey" select="'name:EncryptDecryptKey'"/>
<xsl:variable name="vEncryptedText" select="//*[local-name()='EncryptedText']"/>
<xsl:message>****Encrypted Text: <xsl:value-of select="$vEncryptedText"/>
</xsl:message>
<xsl:message>****Algorithm: <xsl:value-of select="$vAlgorithm"/>
</xsl:message>
<!-- The console log for the text and key are commented out to ensure the logs will not capture the plain text or key, but you may uncomment for debugging. -->
<!--<xsl:message>****Key: <xsl:value-of select="$vKey"/>
</xsl:message>-->
<xsl:variable name="vDecrypt">
<xsl:value-of select="dp:decrypt-data($vAlgorithm,$vKey,$vEncryptedText)"/>
</xsl:variable>
<decryptedResponse>
<decryptedText>
<xsl:value-of select="$vDecrypt"/>
</decryptedText>
</decryptedResponse>
</xsl:template>
</xsl:stylesheet>
Complete DataPower Export of the EncryptDecrypt service with Shared Secret
The export contains the DataPower export of the service creation described in this article. The Crypto Shared Secret is also included in the export, therefore, you’ll just have to import and test with postman.
NOTICE: the port assigned to this service is 8888, therefore if there is anything assigned to port 8888, then you will have to update the HTTP FSH, and make sure you update the Postman testing port also.
https://github.com/ibmArtifacts/encryptdecypt/blob/master/EncryptDecrypt_MPGW.zip