3 Replies Latest reply on Apr 9, 2007 12:54 PM by rick-h

    RSA Encryption Help with Bouncy Castle

    rick-h
      Does anyone have experience doing RSA encryption with Bouncy Castle installed as a security provider?

      For example, what is the proper syntax of the Encrypt(string, key[, algorithm[, encoding]])) function to send an RSA encrypted string to someone given the following values:

      string = "This is the string to encrypt"
      RSA Public Key Moduls = qFP+TNkUxiwqgYkce7iBR1Z2VndmSDLlxM0UQEW5UQQPdTWdEl6iIjteIZr5M9R6EBsGh6XKHG7et9SAJ/0h/OwBJ MOaoGpoQq2IJHKqKA4UhC30fnFZcfVz6ne4dTUemkJinIUiSlHLaChdANoe9lC9wNVGu1tUpkiwj+Pn4/c=
      RSA Public Key Exponent = AQAB
      Padding = pKCS#1 v1.5

      Thanks in advance for any help you can provide.
        • 1. Re: RSA Encryption Help with Bouncy Castle
          c_wigginton Level 1
          <cfsavecontent variable="myText">
          This is a bunch of text that will
          be encrypted in the file.
          </cfsavecontent>


          <cfset myKey = ToBase64("F00BarKey")>

          <b>Encrypted Key</b>
          <p>
          <cfoutput>#myKey#</cfoutput>
          </p>

          <cfset crypText = Encrypt(myText,myKey,"twofish")>

          <cfset deCryptText = Decrypt(crypText,myKey,"twofish")>
          <b>Encrypted Text</b>
          <p>
          <cfoutput>#crypText#</cfoutput>
          </p>
          <p>
          <b>Un-Encrypted Text</b>
          <p>
          <cfoutput>#deCryptText#</cfoutput>
          </p>
          • 2. Re: RSA Encryption Help with Bouncy Castle
            c_wigginton Level 1
            my previous post is only an example using the standard encrypt/decrypt using twofish from bouncy castle. The following link ( http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=e546373d) will give you more information on using Bouncy Castle as a security provider.

            For PGP, most solutions I've seen use either a custom tag, cfexecute, or possibly the Java route ( http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/)

            Hopefully this will give you something to go on.
            • 3. Re: RSA Encryption Help with Bouncy Castle
              rick-h Level 1
              Hi, Thanks for your reply. A couple of clarifications. I need to use the public key provided by the a 3rd party that I am sending encrypted data to, and I must use RSA encryption. I believe what I am looking for will be something like:

              <cfsavecontent variable="myText">
              This is a bunch of text that will
              be encrypted in the file.
              </cfsavecontent>

              <cfset myText_encrypted = encrypt(myText, pubKey, "RSA/NONE/PKCS1Padding")>

              I am not sure how to set the value of pubKey. I have the Base64 encoded modulus and exponent for the 3rd parties Public Key, but I am not sure how to convert the modulus and exponent into the key format that the encrypt() function is looking for.