Hi guys,
Need some help on Asymmetric Encryption in coldfusion webservice
first, I need generate rsa public/private key pair.
I am using CF8 Enterprise version
I download the "Bouncy Castle" API java cryptography library to do that.
My code looks like this
[code]
<!--- Get the Bouncy Castle Asymmetric Key Generator --->
<cfset kpgo = createObject('java',
'org.bouncycastle.jce.provider.asymmetric.ec.KeyPairGenerator') />
<!--- Get an instance of the provider for the RSA algorithm. --->
<cfset kpg = kpgo.getInstance("RSA") />
<!--- Get an instance of secureRandom, we'll need this to initialize the
key generator --->
<cfset sr = createObject('java', 'java.security.SecureRandom').init() />
<!--- Initialize the generator by passing in the size of key we want,
and a strong pseudo-random number generator (PRNG) --->
<cfset kpg.initialize(2048, createObject('java',
'java.security.SecureRandom')) />
<!--- This will create two keys, one public, and one private --->
<cfset kp = kpg.generateKeyPair() />
<!--- Get the two keys. --->
<cfset privateKey = kp.getPrivate() />
<cfset publicKey = kp.getPublic() />
<cffunction name="encryptString" access="public" returntype="Any" output=
"false">
<!--- Take in the string to encrypt and the key to encrypt with --->
<cfargument name="inputString" type="string" />
<cfargument name="key" type="any" />
<!--- Create a Java Cipher object and get a mode --->
<cfset var cipher = createObject('java',
'javax.crypto.Cipher').getInstance("RSA") />
<!--- The mode tells the Cipher whether is will be encrypting or
decrypting --->
<cfset var encMode = cipher.ENCRYPT_MODE />
<cfset var encryptedValue = "" /> <!--- Return variable --->
<!--- Initialize the Cipher with the mode and the key --->
<cfset cipher.init(encMode, key) />
<!--- Convert the string to bytes --->
<cfset stringBytes = inputString.getBytes("UTF8") />
<!--- Perform encryption --->
<cfset encryptedValue = cipher.doFinal(stringBytes, 0, len(inputString))
/>
<cfreturn encryptedValue />
</cffunction>
[/code]
I am actually trying to implement the example from this link
http://www.12robots.com/index.cfm/2010/7/19/Using-Asymmetric-Cryptography-in-your-ColdFusion-Application--Security-Series-1610
I need to use this as a webservice
My webservice will receive 3 parameters (randomTxt, username, password) and
based on that will return the session id along with the public key.
can someone direct me to the correct path?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:339452
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm