|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
IIB9: Custom Decryption |
« View previous topic :: View next topic » |
Author |
Message
|
akil |
Posted: Thu Nov 27, 2014 6:00 am Post subject: IIB9: Custom Decryption |
|
|
 Partisan
Joined: 27 May 2014 Posts: 338 Location: Mumbai
|
Hi
I get an incoming message that has one element encrypted using a RSA public key. I have the private key in a file. This isn't a complete certificate, it is just the key, generated via a small java program
Code: |
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024); // can give the key size for key pair
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(), RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(), RSAPrivateKeySpec.class);
saveToFile("public.key", pub.getModulus(),pub.getPublicExponent());
saveToFile("private.key", priv.getModulus(),priv.getPrivateExponent());
|
Now I have to decrypt this element in the message flow, for which I have to do something like the following code
Code: |
PrivateKey priKey = readKeyFromFile("private.key");
// use the private key for decryption
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, priKey);
decryptedData = cipher.doFinal(dataToDecrypt);
System.out.println(new String(decryptedData));
|
I am wondering how do I proceed with reading this file , earlier posts in the forum suggest that reading files isn't a good thing to do in the bus.
There are multiple environments (QA, UAT, PRD), each having its own private.key, so I can't just package the file along with the code..
Any suggestions?
[/code] _________________ Regards |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Nov 27, 2014 11:06 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Configurable service pointing to the file?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
akil |
Posted: Thu Nov 27, 2014 11:53 pm Post subject: |
|
|
 Partisan
Joined: 27 May 2014 Posts: 338 Location: Mumbai
|
That'll take care of different files paths in different environments..
But do I go ahead and read it in the flow ? _________________ Regards |
|
Back to top |
|
 |
akil |
Posted: Fri Nov 28, 2014 10:06 pm Post subject: |
|
|
 Partisan
Joined: 27 May 2014 Posts: 338 Location: Mumbai
|
So I decided to add 2 properties in the UDCS, the private Exponent & the private Modulus , I build the private key from this , this avoids the file read altogether ..
Interestingly if I name the property to contain the phrase 'Password', the value is masked when mqsireportproperties is called - that's pretty neat !. _________________ Regards |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|