I used DataPower AES encryption method to encrypt a file (see detail below) and send the encrypted file to client. My question is how I can use a OpenSSL command to decrypt the DataPower AES encrypted file to verify if encryption work before I ask our business partner to use OpenSSL Command to decrypt it after our DataPower send the encrypted file to them.
Here are how I implement DataPower encryption using AES
- Using following OpenSSL command to create key and IV
C:\OpenSSL>openssl enc -aes-256-cbc -k secret -P -md sha256
salt=3F5FECB253106AAB
key=EBDDCE6D1D5B911040E304C289E2981107DD52FCD41E87FC2A52C0445F2ED97F
iv =7E3517DE1AB2F826FB984FF0CA8999CA
- Create a DataPower multiple protocol gateway SafehorizonPoller that will poll a file and then encrypt it and send to client, the encryption file encryption_service.xsl is as below
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" xmlns:dp = "http://www.datapower.com/extensions" xmlns:tns = "http://www.nypd.org/SharedKeys" extension-element-prefixes = "dp">
<dp:input-mapping href = "store:///pkcs7-convert-input.ffd" type = "ffd"/>
<xsl:output omit-xml-declaration = "yes"/>
<xsl:template match = "/">
<xsl:variable name = "raw-data" select = "dp:decode(dp:binary-encode(/object/message/node()), 'base-64')"/>
<xsl:variable select="dp:variable('var://context/client/keyVal')" name="lookupKey"/>
<xsl:variable name = "acctkey" select = "document('local:///SharedKeys.xml')//tns:SharedKeys/tns:Accounts/tns:Account[=$lookupKey]"/>
<xsl:variable name = "keyType">
<xsl:value-of select = "string($acctkey//)"/>
</xsl:variable>
<xsl:variable name = "algorithm">
<xsl:value-of select = "$acctkey//tns:Algorithm/text()"/>
</xsl:variable>
<xsl:variable name = "sharedSecretKey">
<xsl:value-of select = "$acctkey//tns:Passphrase/text()"/>
</xsl:variable>
<xsl:variable name = "encrypted" select = "dp:encrypt-string($algorithm,concat($keyType,':',$sharedSecretKey), $raw-data)"/>
<xsl:copy-of select = "$encrypted"/>
</xsl:template>
</xsl:stylesheet>
the key configuration file SharedKeys.xml is below
<?xml version="1.0" encoding="UTF-8"?>
<tns:SharedKeys xmlns:tns = "http://www.nypd.org/SharedKeys" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.nypd.org/SharedKeys SharedKeys.xsd ">
<tns:Accounts>
<tns:Account accountName = "safehorizon_encrypt" keyType = "hex">
<tns:Algorithm>http://www.w3.org/2001/04/xmlenc#aes256-cbc</tns:Algorithm>
<tns:Passphrase>EBDDCE6D1D5B911040E304C289E2981107DD52FCD41E87FC2A52C0445F2ED97F</tns:Passphrase>
</tns:Account>
</tns:Accounts>
</tns:SharedKeys>
The above solution works. I could encrypt a file and decrypt a file using DataPower AES decryption method, which I implemented in a different multiple protocol gateway.
But our business partner will need to use OpenSSL command to decrypt the DataPower AES decrypted file. So I tried using follow OpenSSL command to decrypt the DataPower decrypted file as below
C:\OpenSSL>openssl aes-256-cbc -d -a -in testfile.csv.enc -out testfile.csv -K EBDDCE6D1D5B911040E304C289E2981107DD52FCD41E87FC2A52C0445F2ED97F -iv 7E3517DE1AB2F826FB984FF0CA8999CA
but I got following error
bad decrypt
15212:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:518:
I googled a lot and tried different suggestions. But I failed to make it work. What is the right OpenSSL command to decrypt it?
Thanks,
Tang
#DataPower#Support#SupportMigration