Results 1 to 2 of 2
- 07-05-2011, 05:48 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
Bouncy Castle AES wrapper Key issue
Hi : this is the code:
The problem i am having right now, is that i cannot store the passwordKey which is the key used to wrap my AES key, and if i did tat, it will give me a parameter unknown error ... anyone has any solution?Java Code:public String getPasswordKey() { return Encoder.encode(passwordKey.getEncoded()); } public void setPasswordKey(String key) { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); try { byte[] keys = Encoder.decode(key.toCharArray()); this.passwordKey = new SecretKeySpec(keys, KEY_ALGORITHM); } catch (Exception e) { e.printStackTrace(); } } public String keyWrapper() { Security .addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); Key SharedKey = secret; String key = null; char[] preMaster = this.preMaster().toCharArray(); try { PBEKeySpec keySpec = new PBEKeySpec(preMaster); SecretKeyFactory factory = SecretKeyFactory .getInstance(KEY_ALGORITHM); paramSpec = new PBEParameterSpec(salt, 1024); this.passwordKey = factory.generateSecret(keySpec); Cipher c = Cipher.getInstance(KEY_ALGORITHM); c.init(Cipher.WRAP_MODE, passwordKey, paramSpec); byte[] wrappedKey = c.wrap(SharedKey); key = Encoder.encode(wrappedKey); } catch (Exception e) { e.printStackTrace(); } return key; } public Key keyUnwrapper() { Security .addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); byte[] wrappedKey = sKey; SecretKey unWrapped = null; try { paramSpec = new PBEParameterSpec(salt, 1024); Cipher c = Cipher.getInstance(KEY_ALGORITHM); c.init(Cipher.UNWRAP_MODE, passwordKey, paramSpec); unWrapped =(SecretKey) c.unwrap(wrappedKey, KEY_ALGORITHM, Cipher.SECRET_KEY); } catch (Exception e) { e.printStackTrace(); } return unWrapped; }
- 07-05-2011, 07:52 AM #2
Similar Threads
-
bouncy?
By saintxxrow in forum New To JavaReplies: 1Last Post: 04-08-2009, 01:23 AM -
Secure FTP Wrapper 3.0.3
By Java Tip in forum Java SoftwareReplies: 0Last Post: 07-23-2008, 01:56 PM -
Legion of the Bouncy Castle Java Cryptography API 1.39
By Java Tip in forum Java SoftwareReplies: 0Last Post: 04-03-2008, 04:27 PM -
Legion of the Bouncy Castle Java Cryptography API 1.38
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-12-2007, 05:53 PM -
Legion of the Bouncy Castle Java Cryptography API 1.37
By Jamie in forum Java SoftwareReplies: 0Last Post: 06-16-2007, 09:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks