Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: AES Encryption

  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    78
    Thanks
    1
    Thanked 2 Times in 2 Posts

    AES Encryption

    I find it neccesary to add a new layer of protection; AES Encryption i have written all of the code for the encryption process but it throws an exception that either the key's size is to large or that the default parameters are incorrect.

    Issue #1
    Code:
                            byte[] key = ...... //secret, the byte array has a total of 32 bytes.
                            SecretKeySpec k = new SecretKeySpec(key, "AES");
    			byte[] input = getBytesOfFile(encrypter.current);
    			Cipher cipher = Cipher.getInstance("AES");
    			cipher.init(Cipher.ENCRYPT_MODE, k);
    			byte[] encryptedData = cipher.doFinal(input);
    			Jar.save(encryptedData);

    In PHP i use readfile in combination with a few headers (including) binary to forward any .jar file to java.
    How would i read this in Java and then convert all the bytes to JarFile.

    Code:
    	private class internalLoader extends ClassLoader {
    		public Class<?> clazz;
    
    		public internalLoader(byte[] bytes) {
    			this.clazz = defineClass(selectedScript, bytes, 0, bytes.length);
    			resolveClass(this.clazz);
    			proceed();
    		}
    		private void proceed() {
    			try {
    				script = (Script) clazz.asSubclass(Script.class).newInstance();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    	}
    
    	private byte[] inputStreamToByteArray(InputStream input) throws IOException {
    
    		ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
    
    		byte[] buffer = new byte[512];
    
    		int bytes;
    
    		while ((bytes = input.read(buffer)) > 0) {
    			output.write(buffer, 0, bytes);
    		}
    
    		input.close();
    		return output.toByteArray();
    	}
    
    				byte[] bytes = inputStreamToByteArray((loaderConnection
    						.getInputStream()));
    				new internalLoader(bytes);
    Last edited by BinaryX; 01-26-2011 at 02:50 PM.


 

Posting Permissions

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