Results 1 to 2 of 2
  1. #1
    idtyu is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default Bouncy Castle AES wrapper Key issue

    Hi : this is the code:
    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;
    	}
    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?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Copy and paste the full and exact error message you are getting.

Similar Threads

  1. bouncy?
    By saintxxrow in forum New To Java
    Replies: 1
    Last Post: 04-08-2009, 02:23 AM
  2. Secure FTP Wrapper 3.0.3
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-23-2008, 02:56 PM
  3. Legion of the Bouncy Castle Java Cryptography API 1.39
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-03-2008, 05:27 PM
  4. Legion of the Bouncy Castle Java Cryptography API 1.38
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-12-2007, 06:53 PM
  5. Replies: 0
    Last Post: 06-16-2007, 10:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •