private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase) { if (passphrase == null) return plain; if (cipher == null) cipher = genCipher(); byte[] iv = _iv[0] = new byte[cipher.getIVSize()]; if (random == null) random = genRandom(); random.fill(iv, 0, iv.length); byte[] key = genKey(passphrase, iv); byte[] encoded = plain; // PKCS#5Padding { //int bsize=cipher.getBlockSize(); int bsize = cipher.getIVSize(); byte[] foo = new byte[(encoded.length / bsize + 1) * bsize]; System.arraycopy(encoded, 0, foo, 0, encoded.length); int padding = bsize - encoded.length % bsize; for (int i = foo.length - 1; (foo.length - padding) <= i; i--) { foo[i] = (byte) padding; } encoded = foo; } try { cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.update(encoded, 0, encoded.length, encoded, 0); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } Util.bzero(key); return encoded; }
synchronized byte[] genKey(byte[] passphrase, byte[] iv){ if(cipher==null) cipher=genCipher(); if(hash==null) hash=genHash();
synchronized byte[] genKey(byte[] passphrase, byte[] iv){ if(cipher==null) cipher=genCipher(); if(hash==null) hash=genHash();
synchronized byte[] genKey(byte[] passphrase, byte[] iv){ if(cipher==null) cipher=genCipher(); if(hash==null) hash=genHash();
synchronized byte[] genKey(byte[] passphrase, byte[] iv) { if (cipher == null) cipher = genCipher(); if (hash == null) hash = genHash();
synchronized byte[] genKey(byte[] passphrase, byte[] iv){ if(cipher==null) cipher=genCipher(); if(hash==null) hash=genHash();
private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase){ if(passphrase==null) return plain; if(cipher==null) cipher=genCipher(); byte[] iv=_iv[0]=new byte[cipher.getIVSize()]; if(random==null) random=genRandom(); random.fill(iv, 0, iv.length); byte[] key=genKey(passphrase, iv); byte[] encoded=plain; // PKCS#5Padding { //int bsize=cipher.getBlockSize(); int bsize=cipher.getIVSize(); byte[] foo=new byte[(encoded.length/bsize+1)*bsize]; System.arraycopy(encoded, 0, foo, 0, encoded.length); int padding=bsize-encoded.length%bsize; for(int i=foo.length-1; (foo.length-padding)<=i; i--){ foo[i]=(byte)padding; } encoded=foo; } try{ cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.update(encoded, 0, encoded.length, encoded, 0); } catch(Exception e){ //System.err.println(e); } Util.bzero(key); return encoded; }
private byte[] encrypt(byte[] plain, byte[][] _iv){ if(passphrase==null) return plain; if(cipher==null) cipher=genCipher(); byte[] iv=_iv[0]=new byte[cipher.getIVSize()]; if(random==null) random=genRandom(); random.fill(iv, 0, iv.length); byte[] key=genKey(passphrase, iv); byte[] encoded=plain; // PKCS#5Padding { //int bsize=cipher.getBlockSize(); int bsize=cipher.getIVSize(); byte[] foo=new byte[(encoded.length/bsize+1)*bsize]; System.arraycopy(encoded, 0, foo, 0, encoded.length); int padding=bsize-encoded.length%bsize; for(int i=foo.length-1; (foo.length-padding)<=i; i--){ foo[i]=(byte)padding; } encoded=foo; } try{ cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.update(encoded, 0, encoded.length, encoded, 0); } catch(Exception e){ //System.err.println(e); } Util.bzero(key); return encoded; }
private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase){ if(passphrase==null) return plain; if(cipher==null) cipher=genCipher(); byte[] iv=_iv[0]=new byte[cipher.getIVSize()]; if(random==null) random=genRandom(); random.fill(iv, 0, iv.length); byte[] key=genKey(passphrase, iv); byte[] encoded=plain; // PKCS#5Padding { //int bsize=cipher.getBlockSize(); int bsize=cipher.getIVSize(); byte[] foo=new byte[(encoded.length/bsize+1)*bsize]; System.arraycopy(encoded, 0, foo, 0, encoded.length); int padding=bsize-encoded.length%bsize; for(int i=foo.length-1; (foo.length-padding)<=i; i--){ foo[i]=(byte)padding; } encoded=foo; } try{ cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.update(encoded, 0, encoded.length, encoded, 0); } catch(Exception e){ //System.err.println(e); } Util.bzero(key); return encoded; }
private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase){ if(passphrase==null) return plain; if(cipher==null) cipher=genCipher(); byte[] iv=_iv[0]=new byte[cipher.getIVSize()]; if(random==null) random=genRandom(); random.fill(iv, 0, iv.length); byte[] key=genKey(passphrase, iv); byte[] encoded=plain; // PKCS#5Padding { //int bsize=cipher.getBlockSize(); int bsize=cipher.getIVSize(); byte[] foo=new byte[(encoded.length/bsize+1)*bsize]; System.arraycopy(encoded, 0, foo, 0, encoded.length); int padding=bsize-encoded.length%bsize; for(int i=foo.length-1; (foo.length-padding)<=i; i--){ foo[i]=(byte)padding; } encoded=foo; } try{ cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.update(encoded, 0, encoded.length, encoded, 0); } catch(Exception e){ //System.err.println(e); } Util.bzero(key); return encoded; }