Topic
  • 2 replies
  • Latest Post - ‏2013-04-26T22:50:45Z by JoeMorganNTST
JoeMorganNTST
JoeMorganNTST
427 Posts

Pinned topic How to use encrypt-string?

‏2013-04-26T19:00:34Z |

Has anyone successfully used the "encrypt-string" function?  I swear I've tried every variation of the thing and cannot make it work.  The only thing it seems to be able to do is to tell me '*Invalid key length for algorithm*'.

I've tried the "name:SSKeyObject" and "key:GoobledyGookBase64Key" on an AES256 key generated from OpenSSL.

Does anyone have something that works and how they generated the key?

 

 

 

  • HermannSW
    HermannSW
    4657 Posts
    ACCEPTED ANSWER

    Re: How to use encrypt-string?

    ‏2013-04-26T21:21:49Z  

    Here is a working sample:

    $ echo "<foobar/>" | coproc2 encrypt-string.xsl - http://dp2-l3:2223
    8YieC3REAd75ecVWy/5uOQ==
    Fo1mUz5v86rfTHzpufqYp2s6G9dj6CtR4Lps6o+dMwA=
    $
    $ cat encrypt-string.xsl
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:output omit-xml-declaration="yes" />
        
      <xsl:template match="/">
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#tripledes-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#aes128-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
      </xsl:template>
     
    </xsl:stylesheet>
    $
     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

     

  • HermannSW
    HermannSW
    4657 Posts

    Re: How to use encrypt-string?

    ‏2013-04-26T21:21:49Z  

    Here is a working sample:

    $ echo "<foobar/>" | coproc2 encrypt-string.xsl - http://dp2-l3:2223
    8YieC3REAd75ecVWy/5uOQ==
    Fo1mUz5v86rfTHzpufqYp2s6G9dj6CtR4Lps6o+dMwA=
    $
    $ cat encrypt-string.xsl
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:output omit-xml-declaration="yes" />
        
      <xsl:template match="/">
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#tripledes-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#aes128-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
      </xsl:template>
     
    </xsl:stylesheet>
    $
     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

     

  • JoeMorganNTST
    JoeMorganNTST
    427 Posts

    Re: How to use encrypt-string?

    ‏2013-04-26T22:50:45Z  
    • HermannSW
    • ‏2013-04-26T21:21:49Z

    Here is a working sample:

    $ echo "<foobar/>" | coproc2 encrypt-string.xsl - http://dp2-l3:2223
    8YieC3REAd75ecVWy/5uOQ==
    Fo1mUz5v86rfTHzpufqYp2s6G9dj6CtR4Lps6o+dMwA=
    $
    $ cat encrypt-string.xsl
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:output omit-xml-declaration="yes" />
        
      <xsl:template match="/">
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#tripledes-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:value-of
          select="dp:encrypt-string(
                    'http://www.w3.org/2001/04/xmlenc#aes128-cbc',
                    'hex:0123456789ABCDEF0123456789ABCDEF',
                    'test'
                  )"/>
        <xsl:text>&#10;</xsl:text>
      </xsl:template>
     
    </xsl:stylesheet>
    $
     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

     

    Sorry it took me all day to get back to it.. but... that is perfect.  I didn't think of just dropping in the keydata itself, but that's just what I needed.

    Do you know a reason why this didn't work when using "name:SSKeyObjectName" when that mapped to a file containing the key data?


    Edit: 2013-04-29

    Now I know why.  When I generated the AES 256 key, it generated the key in Hex, and I stupidly assumed it was in Base 64.  This is why it only worked with the "hex:xxx" form of the function and not the "key:xxx" and "name:ObjName" forms, which both require Base 64.

     

    Updated on 2013-04-29T14:00:38Z at 2013-04-29T14:00:38Z by JoeMorganNTST