Working with stored RSA key files with Bouncy Castle and JBuilder 2005
I followed the examples of Michael Juntao Yuan at http://www.javaworld.com/javaworld/jw-12-2002/jw-1220-wireless.html
the program read RSA key files using the following code
SecureRandom sr = new SecureRandom();
salt = new byte [16];
sr.nextBytes(salt);
is = c.getResourceAsStream("res/keys/RSAmod.dat");
BigInteger RSAmod = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAprivExp.dat");
BigInteger RSAprivExp = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSApubExp.dat");
BigInteger RSApubExp = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAdp.dat");
BigInteger RSAdp = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAdq.dat");
BigInteger RSAdq = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAp.dat");
BigInteger RSAp = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAq.dat");
BigInteger RSAq = new BigInteger(readFromStream(is));
is.close();
is = c.getResourceAsStream("res/keys/RSAqInv.dat");
BigInteger RSAqInv = new BigInteger(readFromStream(is));
is.close();
private byte [] readFromStream (InputStream is) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte [] b = new byte[1];
while ( is.read(b) != -1 ) {
is.read(b);
baos.write(b);
}
byte[] result = baos.toByteArray();
baos.close();
return result;
}
I have checked that the keys file were included in the jar file, but when running the program it always return java.lang.NullPointerException. Are there any other setting needed to make the keys from avaiable for the program using JBuilder2005?
And is it correct that the keys file stored in jar file as /res/keys/*.*?
Many Thanks