473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

KeyStore Persistence

Hi,

i have developed a code for encryption and decryption of credit card number.
For this i am using java.security.KeyStore.

I have created public and private keys and a certificate and stored them in this KeyStore. I am able to retreive the keys and certificate from the keystore,.
BUT i a not able to store this keystore ( or make it persist).

I need to persist this keystore so that i can load it in other file and extract the information from it.

Please tell me how to store this keystore.


I am using this code :




com.ibm.security.x509.CertAndKeyGen keypair;

keypair = new com.ibm.security.x509.CertAndKeyGen("RSA",
"MD5WithRSA");
com.ibm.security.x509.X500Name x500Name;

x500Name = new com.ibm.security.x509.X500Name("IGEL RemoteManager",
"IGEL Technology GmbH", "IGEL Technology GmbH", "DE");
keypair.generate(1024);
PrivateKey thisPrivateKey = keypair.getPrivateKey();
PublicKey thisPublicKey = keypair.getPublicKey();
System.out.println("Private Key : " + thisPrivateKey);
System.out.println("Private Key : " + thisPublicKey);
java.security.cert.X509Certificate[] chain = new java.security.cert.X509Certificate[1];

chain[0] = keypair
.getSelfCertificate(x500Name, 7000 * 24 * 60 * 60);

System.out.println("chain " + chain[0]);
Key key = (Key) (thisPrivateKey);
//Certificate cert = (Certificate)(chain[0]);
String str = "ABC";
char ch[] = str.toCharArray();

KeyStore ks;

ks = KeyStore.getInstance(KeyStore.getDefaultType());
// String keyStoreType = KeyStore.getDefaultType();
// System.out.println("keyStoreType is ---"+keyStoreType);
// Provider provider = ks.getProvider();
// System.out.println("Provider***********"+provider) ;

ks.load(null, ch);



ks.setKeyEntry("alias", key, ch, chain);
System.out.println(ks.getCertificate("alias"));

FileOutputStream fos = new FileOutputStream("d:/Girish2.keystore");
ks.store(fos, ch);
fos.close();
System.out.println("KeyStore is **************" +ks.toString());

X509Certificate car = (com.ibm.security.x509.X509CertImpl) ks
.getCertificate("alias");
//X509CertImpl car = ( X509CertImpl) ks.getCertificate("alias");
System.out.println("Certificate is +++++++++++++++" + car);

System.out.println("******************" + ks.getKey("alias", ch));

SecureRandom srandom = new SecureRandom();

Cipher cp;

cp = Cipher.getInstance("RSA/ECB/PKCS1Padding");

cp.init(Cipher.ENCRYPT_MODE, car, srandom);
// PrivateKey pkEntry = (PrivateKey)ks.getKey("testalias",ch1);

String input = "1234567890123456";

byte[] inputBytes = input.getBytes();

byte[] encryptedBytes;

encryptedBytes = cp.doFinal(inputBytes);
System.out.println("certificate--" + car);
System.out.println("Encrypted Code-----" + encryptedBytes);

Random rand = new Random(1000);
Integer ixd = new Integer(rand.nextInt());
entityHome = (EncryptEntityHome) PortableRemoteObject.narrow(obj,
EncryptEntityHome.class);
encryptEntity = entityHome.create(new Integer(100));
encryptEntity.setAlias("alias");
encryptEntity.setEncryptString(encryptedBytes.toSt ring());
System.out.println("Encrypt Entity is : " + encryptEntity);
May 15 '07 #1
0 1327

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: PerfectDayToChaseTornados | last post by:
Hi All, I'm interested in peoples opinions & experiences of various persistence frameworks. I mainly use EJB2 or straight JDBC for persistence, but have been looking at various alternative...
6
by: Paolo Losi | last post by:
Hi all, I'm pretty new to the python language so please excuse me if this is FAQ... I'm very glad to be part of the list! :-) I'm looking into a way to implement a generic workflow framework...
1
by: Joe | last post by:
I was wondering if there are any recommended persistence frameworks for use in .NET that could be recommended. I am looking for the following requirements: Free/Open Source or very inexpensive....
10
by: Simon Harvey | last post by:
Hi everyone, Can anyone tell me if I declare a global variable in my pages code behind, is it persisted if the page does a post back, or do I need to add the object to the session object in...
2
by: dkode | last post by:
Hello, I am laying out the architecture for a very large website that will scale to a very large degree. I have a couple of questions before I attempt to go and implement a Broker/Persistence...
5
by: Chris Spencer | last post by:
Before I get too carried away with something that's probably unnecessary, please allow me to throw around some ideas. I've been looking for a method of transparent, scalable, and human-readable...
0
by: Gardner | last post by:
I am trying to send a digitally signed xml from server A to B. I want to do the following steps offline - 1. Create an RSA pair on server A. 2. Export the public key to an xml file. 3. Copy the...
0
myusernotyours
by: myusernotyours | last post by:
Hi all, Am trying to create a Java Desktop App that uses Java Persistence in Netbeans. The database is MS Access but I tried with Mysql and got the same error. When I run the app( Create the...
0
by: marley101 | last post by:
Hi there Im having trouble converting a java keystore to X509 certificate and using in vb .net I have exported using Portecle in to .pem format. This works under php, but doesnt seem to in vb...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.