Loading ...
Sorry, an error occurred while loading the content.
 

Encryption in Flex and Decryption in ColdFusion.

Expand Messages
  • ivansebastiansurya
    Hi there, Has anyone attempted to encode some string in Flex and decode it in COldFusion? I ve attempted to encode the string using the library in
    Message 1 of 7 , Dec 5, 2007
      Hi there,

      Has anyone attempted to encode some string in Flex and decode it in
      COldFusion?
      I've attempted to encode the string using the library in
      http://crypto.hurlant.com/
      as follows:
      var key:ByteArray = Hex.toArray(model.hashKey); // some key
      var cipher:ICipher = Crypto.getCipher("aes", key);
      var rawData:ByteArray = Hex.toArray(dataToEncrypt);
      I then send the encrypted data as a string (Hex.fromArray
      (encryptedByteArray).

      I then try to decrypt it in ColdFusion, using:
      decrypted=decrypt(arguments.xmlString,
      application.hashkey, "AES", "Hex");

      , but it doesn't seem to work.

      If anyone can help me out, that would be greatly appreciated.
      Thanks,

      Ivan.
    • Jeffry Houser
      Which library? I ve been able to successfully pass data back and forth between Flex and Crypto using AES. There are settings you need to specify (128 bit
      Message 2 of 7 , Dec 5, 2007
        Which library?

        I've been able to successfully pass data back and forth between Flex
        and Crypto using AES.

        There are settings you need to specify (128 bit something?), but w/o
        pulling the code, I don't remember them.

        ivansebastiansurya wrote:
        >
        >
        > Hi there,
        >
        > Has anyone attempted to encode some string in Flex and decode it in
        > COldFusion?
        > I've attempted to encode the string using the library in
        > http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
        > as follows:
        > var key:ByteArray = Hex.toArray(model.hashKey); // some key
        > var cipher:ICipher = Crypto.getCipher("aes", key);
        > var rawData:ByteArray = Hex.toArray(dataToEncrypt);
        > I then send the encrypted data as a string (Hex.fromArray
        > (encryptedByteArray).
        >
        > I then try to decrypt it in ColdFusion, using:
        > decrypted=decrypt(arguments.xmlString,
        > application.hashkey, "AES", "Hex");
        >
        > , but it doesn't seem to work.
        >
        > If anyone can help me out, that would be greatly appreciated.
        > Thanks,
        >
        > Ivan.
        >
        >

        --
        Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
        Recording Engineer
        AIM: Reboog711 | Phone: 1-203-379-0773
        --
        My Company: <http://www.dot-com-it.com>
        My Podcast: <http://www.theflexshow.com>
        My Blog: <http://www.jeffryhouser.com>
      • ivansebastiansurya
        Crypto? You mean ColdFusion? Seems like I can t decode the encoded string. Thanks. I use the library at http://crypto.hurlant.com/ Thanks, Ivan. ... Flex ...
        Message 3 of 7 , Dec 5, 2007
          Crypto? You mean ColdFusion?
          Seems like I can't decode the encoded string.
          Thanks.

          I use the library at http://crypto.hurlant.com/
          Thanks,

          Ivan.

          --- In flexcoders@yahoogroups.com, Jeffry Houser <jeff@...> wrote:
          >
          >
          > Which library?
          >
          > I've been able to successfully pass data back and forth between
          Flex
          > and Crypto using AES.
          >
          > There are settings you need to specify (128 bit something?), but
          w/o
          > pulling the code, I don't remember them.
          >
          > ivansebastiansurya wrote:
          > >
          > >
          > > Hi there,
          > >
          > > Has anyone attempted to encode some string in Flex and decode it
          in
          > > COldFusion?
          > > I've attempted to encode the string using the library in
          > > http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
          > > as follows:
          > > var key:ByteArray = Hex.toArray(model.hashKey); // some key
          > > var cipher:ICipher = Crypto.getCipher("aes", key);
          > > var rawData:ByteArray = Hex.toArray(dataToEncrypt);
          > > I then send the encrypted data as a string (Hex.fromArray
          > > (encryptedByteArray).
          > >
          > > I then try to decrypt it in ColdFusion, using:
          > > decrypted=decrypt(arguments.xmlString,
          > > application.hashkey, "AES", "Hex");
          > >
          > > , but it doesn't seem to work.
          > >
          > > If anyone can help me out, that would be greatly appreciated.
          > > Thanks,
          > >
          > > Ivan.
          > >
          > >
          >
          > --
          > Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
          > Recording Engineer
          > AIM: Reboog711 | Phone: 1-203-379-0773
          > --
          > My Company: <http://www.dot-com-it.com>
          > My Podcast: <http://www.theflexshow.com>
          > My Blog: <http://www.jeffryhouser.com>
          >
        • Jeffry Houser
          By Crypto I meant the AS3 library you link to, which is named As3 Crypto . I m pulled up my code. You should be able to use the CryptoDemo to create a Key in
          Message 4 of 7 , Dec 5, 2007
            By Crypto I meant the AS3 library you link to, which is named "As3
            Crypto". I'm pulled up my code.

            You should be able to use the CryptoDemo to create a Key in Hex. Once
            you have the key, you should be able to do something like this in CF:

            <cfset HexKey = "8738fed68e7677d374e0946c8f7bd3bb">
            <cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>

            <cfset PlainText = "This is a Test">
            <Cfset Encrypted = Encrypt(PlainText, MyKey, 'AES','Hex')>
            <Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>

            <cfoutput>
            Hex Key: #HexKey#<br />
            Key as string: #hexToString(HexKey)#<Br>
            Key: #MyKey#<Br>

            Plain Text: #PlainText#<br>
            Encrypted: #Encrypted#<Br>
            Decrypted: #Decrypted#<br>
            </cfoutput>


            You'll probably want something a bit more 'dynamic' but hopefully this
            will get you going. I haven't looked at it in months, so the code is
            not fresh in my mind...



            ivansebastiansurya wrote:
            >
            >
            > Crypto? You mean ColdFusion?
            > Seems like I can't decode the encoded string.
            > Thanks.
            >
            > I use the library at http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
            > Thanks,
            >
            > Ivan.
            >
            > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>,
            > Jeffry Houser <jeff@...> wrote:
            > >
            > >
            > > Which library?
            > >
            > > I've been able to successfully pass data back and forth between
            > Flex
            > > and Crypto using AES.
            > >
            > > There are settings you need to specify (128 bit something?), but
            > w/o
            > > pulling the code, I don't remember them.
            > >
            > > ivansebastiansurya wrote:
            > > >
            > > >
            > > > Hi there,
            > > >
            > > > Has anyone attempted to encode some string in Flex and decode it
            > in
            > > > COldFusion?
            > > > I've attempted to encode the string using the library in
            > > > http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
            > <http://crypto.hurlant.com/ <http://crypto.hurlant.com/>>
            > > > as follows:
            > > > var key:ByteArray = Hex.toArray(model.hashKey); // some key
            > > > var cipher:ICipher = Crypto.getCipher("aes", key);
            > > > var rawData:ByteArray = Hex.toArray(dataToEncrypt);
            > > > I then send the encrypted data as a string (Hex.fromArray
            > > > (encryptedByteArray).
            > > >
            > > > I then try to decrypt it in ColdFusion, using:
            > > > decrypted=decrypt(arguments.xmlString,
            > > > application.hashkey, "AES", "Hex");
            > > >
            > > > , but it doesn't seem to work.
            > > >
            > > > If anyone can help me out, that would be greatly appreciated.
            > > > Thanks,
            > > >
            > > > Ivan.
            > > >
            > > >
            > >
            > > --
            > > Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
            > > Recording Engineer
            > > AIM: Reboog711 | Phone: 1-203-379-0773
            > > --
            > > My Company: <http://www.dot-com-it.com <http://www.dot-com-it.com>>
            > > My Podcast: <http://www.theflexshow.com <http://www.theflexshow.com>>
            > > My Blog: <http://www.jeffryhouser.com <http://www.jeffryhouser.com>>
            > >
            >
            >

            --
            Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
            Recording Engineer
            AIM: Reboog711 | Phone: 1-203-379-0773
            --
            My Company: <http://www.dot-com-it.com>
            My Podcast: <http://www.theflexshow.com>
            My Blog: <http://www.jeffryhouser.com>
          • ivansebastiansurya
            Hi, Thanks for your help, But I still got different result for encrypting in Flex using the crypto library: var key:ByteArray =
            Message 5 of 7 , Dec 5, 2007
              Hi,

              Thanks for your help,

              But I still got different result for encrypting in Flex using the
              crypto library:

              var key:ByteArray = Hex.toArray("4cb3c6af71194975d7a7679635c44517");
              var cipher:ICipher = Crypto.getCipher("aes", key);
              var rawData:ByteArray = Hex.toArray(Hex.fromString("This is a
              Test")); // I suppose you convert the string to hex first, then to
              // byte array.
              cipher.encrypt(rawData);
              ti_encodedText.text = Hex.fromArray(rawData); // to print it out,
              // need to convert it to hex string first???

              This gives me: 28c8f58f6858ea48ed85c88fb2a5fd69

              But in ColdFusion below:

              <cfset HexKey = "4cb3c6af71194975d7a7679635c44517">
              <cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>

              <cfset PlainText = "This is a Test">
              <Cfset Encrypted = Encrypt(PlainText, MyKey, 'AES','Hex')>
              <Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>

              <cfoutput>
              Hex Key: #HexKey#<br />
              Key: #MyKey#<Br>

              Plain Text: #PlainText#<br>
              Encrypted: #Encrypted#<Br>
              Decrypted: #Decrypted#<br>
              </cfoutput>

              The encrypted text is 14C561515CA3283C297EEC0A99E80D08

              So I got different result for encrypting the same text using the
              same key.

              Do you have any idea why this is the case?

              Thanks,

              Ivan.
              --- In flexcoders@yahoogroups.com, Jeffry Houser <jeff@...> wrote:
              >
              >
              > By Crypto I meant the AS3 library you link to, which is
              named "As3
              > Crypto". I'm pulled up my code.
              >
              > You should be able to use the CryptoDemo to create a Key in
              Hex. Once
              > you have the key, you should be able to do something like this in
              CF:
              >
              > <cfset HexKey = "8738fed68e7677d374e0946c8f7bd3bb">
              > <cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>
              >
              > <cfset PlainText = "This is a Test">
              > <Cfset Encrypted = Encrypt(PlainText, MyKey, 'AES','Hex')>
              > <Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>
              >
              > <cfoutput>
              > Hex Key: #HexKey#<br />
              > Key as string: #hexToString(HexKey)#<Br>
              > Key: #MyKey#<Br>
              >
              > Plain Text: #PlainText#<br>
              > Encrypted: #Encrypted#<Br>
              > Decrypted: #Decrypted#<br>
              > </cfoutput>
              >
              >
              > You'll probably want something a bit more 'dynamic' but
              hopefully this
              > will get you going. I haven't looked at it in months, so the code
              is
              > not fresh in my mind...
              >
              >
              >
              > ivansebastiansurya wrote:
              > >
              > >
              > > Crypto? You mean ColdFusion?
              > > Seems like I can't decode the encoded string.
              > > Thanks.
              > >
              > > I use the library at http://crypto.hurlant.com/
              <http://crypto.hurlant.com/>
              > > Thanks,
              > >
              > > Ivan.
              > >
              > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%
              40yahoogroups.com>,
              > > Jeffry Houser <jeff@> wrote:
              > > >
              > > >
              > > > Which library?
              > > >
              > > > I've been able to successfully pass data back and forth
              between
              > > Flex
              > > > and Crypto using AES.
              > > >
              > > > There are settings you need to specify (128 bit something?),
              but
              > > w/o
              > > > pulling the code, I don't remember them.
              > > >
              > > > ivansebastiansurya wrote:
              > > > >
              > > > >
              > > > > Hi there,
              > > > >
              > > > > Has anyone attempted to encode some string in Flex and
              decode it
              > > in
              > > > > COldFusion?
              > > > > I've attempted to encode the string using the library in
              > > > > http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
              > > <http://crypto.hurlant.com/ <http://crypto.hurlant.com/>>
              > > > > as follows:
              > > > > var key:ByteArray = Hex.toArray(model.hashKey); // some key
              > > > > var cipher:ICipher = Crypto.getCipher("aes", key);
              > > > > var rawData:ByteArray = Hex.toArray(dataToEncrypt);
              > > > > I then send the encrypted data as a string (Hex.fromArray
              > > > > (encryptedByteArray).
              > > > >
              > > > > I then try to decrypt it in ColdFusion, using:
              > > > > decrypted=decrypt(arguments.xmlString,
              > > > > application.hashkey, "AES", "Hex");
              > > > >
              > > > > , but it doesn't seem to work.
              > > > >
              > > > > If anyone can help me out, that would be greatly
              appreciated.
              > > > > Thanks,
              > > > >
              > > > > Ivan.
              > > > >
              > > > >
              > > >
              > > > --
              > > > Jeffry Houser, Technical Entrepreneur, Software Developer,
              Author,
              > > > Recording Engineer
              > > > AIM: Reboog711 | Phone: 1-203-379-0773
              > > > --
              > > > My Company: <http://www.dot-com-it.com <http://www.dot-com-
              it.com>>
              > > > My Podcast: <http://www.theflexshow.com
              <http://www.theflexshow.com>>
              > > > My Blog: <http://www.jeffryhouser.com
              <http://www.jeffryhouser.com>>
              > > >
              > >
              > >
              >
              > --
              > Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
              > Recording Engineer
              > AIM: Reboog711 | Phone: 1-203-379-0773
              > --
              > My Company: <http://www.dot-com-it.com>
              > My Podcast: <http://www.theflexshow.com>
              > My Blog: <http://www.jeffryhouser.com>
              >
            • ivansebastiansurya
              And if I attempt to decrypt in ColdFusion what I ve encrypted in Flex, I got: An error occurred while trying to encrypt or decrypt your input string:
              Message 6 of 7 , Dec 5, 2007
                And if I attempt to decrypt in ColdFusion what I've encrypted in
                Flex, I got:
                An error occurred while trying to encrypt or decrypt your input
                string: com.rsa.jsafe.crypto.dr: Could not perform unpadding:
                invalid pad byte..

                It would be great if you can help me out. All I need to do is
                encrypt it so that CF can decrypt it.
                Thanks in advance.

                --- In flexcoders@yahoogroups.com, "ivansebastiansurya"
                <ivansebastiansurya@...> wrote:
                >
                > Hi,
                >
                > Thanks for your help,
                >
                > But I still got different result for encrypting in Flex using the
                > crypto library:
                >
                > var key:ByteArray = Hex.toArray
                ("4cb3c6af71194975d7a7679635c44517");
                > var cipher:ICipher = Crypto.getCipher("aes", key);
                > var rawData:ByteArray = Hex.toArray(Hex.fromString("This is a
                > Test")); // I suppose you convert the string to hex first, then to
                > // byte array.
                > cipher.encrypt(rawData);
                > ti_encodedText.text = Hex.fromArray(rawData); // to print it out,
                > // need to convert it to hex string first???
                >
                > This gives me: 28c8f58f6858ea48ed85c88fb2a5fd69
                >
                > But in ColdFusion below:
                >
                > <cfset HexKey = "4cb3c6af71194975d7a7679635c44517">
                > <cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>
                >
                > <cfset PlainText = "This is a Test">
                > <Cfset Encrypted = Encrypt(PlainText, MyKey, 'AES','Hex')>
                > <Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>
                >
                > <cfoutput>
                > Hex Key: #HexKey#<br />
                > Key: #MyKey#<Br>
                >
                > Plain Text: #PlainText#<br>
                > Encrypted: #Encrypted#<Br>
                > Decrypted: #Decrypted#<br>
                > </cfoutput>
                >
                > The encrypted text is 14C561515CA3283C297EEC0A99E80D08
                >
                > So I got different result for encrypting the same text using the
                > same key.
                >
                > Do you have any idea why this is the case?
                >
                > Thanks,
                >
                > Ivan.
                > --- In flexcoders@yahoogroups.com, Jeffry Houser <jeff@> wrote:
                > >
                > >
                > > By Crypto I meant the AS3 library you link to, which is
                > named "As3
                > > Crypto". I'm pulled up my code.
                > >
                > > You should be able to use the CryptoDemo to create a Key in
                > Hex. Once
                > > you have the key, you should be able to do something like this
                in
                > CF:
                > >
                > > <cfset HexKey = "8738fed68e7677d374e0946c8f7bd3bb">
                > > <cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>
                > >
                > > <cfset PlainText = "This is a Test">
                > > <Cfset Encrypted = Encrypt(PlainText, MyKey, 'AES','Hex')>
                > > <Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>
                > >
                > > <cfoutput>
                > > Hex Key: #HexKey#<br />
                > > Key as string: #hexToString(HexKey)#<Br>
                > > Key: #MyKey#<Br>
                > >
                > > Plain Text: #PlainText#<br>
                > > Encrypted: #Encrypted#<Br>
                > > Decrypted: #Decrypted#<br>
                > > </cfoutput>
                > >
                > >
                > > You'll probably want something a bit more 'dynamic' but
                > hopefully this
                > > will get you going. I haven't looked at it in months, so the
                code
                > is
                > > not fresh in my mind...
                > >
                > >
                > >
                > > ivansebastiansurya wrote:
                > > >
                > > >
                > > > Crypto? You mean ColdFusion?
                > > > Seems like I can't decode the encoded string.
                > > > Thanks.
                > > >
                > > > I use the library at http://crypto.hurlant.com/
                > <http://crypto.hurlant.com/>
                > > > Thanks,
                > > >
                > > > Ivan.
                > > >
                > > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%
                > 40yahoogroups.com>,
                > > > Jeffry Houser <jeff@> wrote:
                > > > >
                > > > >
                > > > > Which library?
                > > > >
                > > > > I've been able to successfully pass data back and forth
                > between
                > > > Flex
                > > > > and Crypto using AES.
                > > > >
                > > > > There are settings you need to specify (128 bit
                something?),
                > but
                > > > w/o
                > > > > pulling the code, I don't remember them.
                > > > >
                > > > > ivansebastiansurya wrote:
                > > > > >
                > > > > >
                > > > > > Hi there,
                > > > > >
                > > > > > Has anyone attempted to encode some string in Flex and
                > decode it
                > > > in
                > > > > > COldFusion?
                > > > > > I've attempted to encode the string using the library in
                > > > > > http://crypto.hurlant.com/ <http://crypto.hurlant.com/>
                > > > <http://crypto.hurlant.com/ <http://crypto.hurlant.com/>>
                > > > > > as follows:
                > > > > > var key:ByteArray = Hex.toArray(model.hashKey); // some
                key
                > > > > > var cipher:ICipher = Crypto.getCipher("aes", key);
                > > > > > var rawData:ByteArray = Hex.toArray(dataToEncrypt);
                > > > > > I then send the encrypted data as a string (Hex.fromArray
                > > > > > (encryptedByteArray).
                > > > > >
                > > > > > I then try to decrypt it in ColdFusion, using:
                > > > > > decrypted=decrypt(arguments.xmlString,
                > > > > > application.hashkey, "AES", "Hex");
                > > > > >
                > > > > > , but it doesn't seem to work.
                > > > > >
                > > > > > If anyone can help me out, that would be greatly
                > appreciated.
                > > > > > Thanks,
                > > > > >
                > > > > > Ivan.
                > > > > >
                > > > > >
                > > > >
                > > > > --
                > > > > Jeffry Houser, Technical Entrepreneur, Software Developer,
                > Author,
                > > > > Recording Engineer
                > > > > AIM: Reboog711 | Phone: 1-203-379-0773
                > > > > --
                > > > > My Company: <http://www.dot-com-it.com <http://www.dot-com-
                > it.com>>
                > > > > My Podcast: <http://www.theflexshow.com
                > <http://www.theflexshow.com>>
                > > > > My Blog: <http://www.jeffryhouser.com
                > <http://www.jeffryhouser.com>>
                > > > >
                > > >
                > > >
                > >
                > > --
                > > Jeffry Houser, Technical Entrepreneur, Software Developer,
                Author,
                > > Recording Engineer
                > > AIM: Reboog711 | Phone: 1-203-379-0773
                > > --
                > > My Company: <http://www.dot-com-it.com>
                > > My Podcast: <http://www.theflexshow.com>
                > > My Blog: <http://www.jeffryhouser.com>
                > >
                >
              • Jeffry Houser
                I ve been told that sometimes this happens, but the data can still be decrypted correctly by the alternate source. ( I haven t experienced this myself, mind
                Message 7 of 7 , Dec 5, 2007
                  I've been told that sometimes this happens, but the data can still be
                  decrypted correctly by the alternate source. ( I haven't experienced
                  this myself, mind you ).

                  Most likely you have some setting wrong on the Flex side. I can't
                  find my notes, but from memroy..

                  Encryption: AES
                  Mode: ECB
                  Padding: PKC#5
                  Key Format: HEX
                  Plain Text: Text
                  Cipher Text: HEX

                  I remember not using an initialization vector

                  ivansebastiansurya wrote:
                  >
                  > So I got different result for encrypting the same text using the
                  > same key.
                  >
                  > Do you have any idea why this is the case?
                  >
                  > Thanks,
                  >
                  > Ivan.

                  --
                  Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
                  Recording Engineer
                  AIM: Reboog711 | Phone: 1-203-379-0773
                  --
                  My Company: <http://www.dot-com-it.com>
                  My Podcast: <http://www.theflexshow.com>
                  My Blog: <http://www.jeffryhouser.com>
                Your message has been successfully submitted and would be delivered to recipients shortly.