/** * Gets a random initialization vector. * @param len the length of the initialization vector * @return a random initialization vector */ public static byte[] getIV(int len) { byte[] b = new byte[len]; synchronized (arcfour) { arcfour.encryptARCFOUR(b); } return b; } }
public void encryptARCFOUR(byte data[]) { encryptARCFOUR(data, 0, data.length, data, 0); } }
/** * Gets a random initialization vector. * @param len the length of the initialization vector * @return a random initialization vector */ public static byte[] getIV(int len) { byte[] b = new byte[len]; synchronized (arcfour) { arcfour.encryptARCFOUR(b); } return b; } }
public void encryptARCFOUR(byte[] data) { encryptARCFOUR(data, 0, data.length, data, 0); } }
/** * Gets a random initialization vector. * @param len the length of the initialization vector * @return a random initialization vector */ public static byte[] getIV(int len) { byte[] b = new byte[len]; synchronized (arcfour) { arcfour.encryptARCFOUR(b); } return b; } }
public void encryptARCFOUR(byte data[]) { encryptARCFOUR(data, 0, data.length, data, 0); } }
public void encryptARCFOUR(byte data[], int off, int len) { encryptARCFOUR(data, off, len, data, off); }
public void encryptARCFOUR(byte dataIn[], byte dataOut[]) { encryptARCFOUR(dataIn, 0, dataIn.length, dataOut, 0); }
public void encryptARCFOUR(byte[] dataIn, byte[] dataOut) { encryptARCFOUR(dataIn, 0, dataIn.length, dataOut, 0); }
public void encryptARCFOUR(byte data[], int off, int len) { encryptARCFOUR(data, off, len, data, off); }
public void encryptARCFOUR(byte[] data, int off, int len) { encryptARCFOUR(data, off, len, data, off); }
public void encryptARCFOUR(byte dataIn[], byte dataOut[]) { encryptARCFOUR(dataIn, 0, dataIn.length, dataOut, 0); }
/** * * mkey must be setup */ // use the revision to choose the setup method private void setupUserKey() { if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { md5.update(pad); byte digest[] = md5.digest(documentID); System.arraycopy(digest, 0, userKey, 0, 16); for (int k = 16; k < 32; ++k) userKey[k] = 0; for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) digest[j] = (byte) (mkey[j] ^ i); arcfour.prepareARCFOURKey(digest, 0, mkey.length); arcfour.encryptARCFOUR(userKey, 0, 16); } } else { arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(pad, userKey); } }
/** */ private byte[] computeOwnerKey(byte[] userPad, byte[] ownerPad) { byte[] ownerKey = new byte[32]; byte[] digest = md5.digest(ownerPad); if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { byte[] mkey = new byte[keyLength / 8]; // only use for the input as many bit as the key consists of for (int k = 0; k < 50; ++k) System.arraycopy(md5.digest(digest), 0, digest, 0, mkey.length); System.arraycopy(userPad, 0, ownerKey, 0, 32); for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) mkey[j] = (byte) (digest[j] ^ i); arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(ownerKey); } } else { arcfour.prepareARCFOURKey(digest, 0, 5); arcfour.encryptARCFOUR(userPad, ownerKey); } return ownerKey; }
/** * * mkey must be setup */ // use the revision to choose the setup method private void setupUserKey() { if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { md5.update(pad); byte[] digest = md5.digest(documentID); System.arraycopy(digest, 0, userKey, 0, 16); for (int k = 16; k < 32; ++k) userKey[k] = 0; for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) digest[j] = (byte) (mkey[j] ^ i); arcfour.prepareARCFOURKey(digest, 0, mkey.length); arcfour.encryptARCFOUR(userKey, 0, 16); } } else { arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(pad, userKey); } }
/** * * mkey must be setup */ // use the revision to choose the setup method private void setupUserKey() { if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { md5.update(pad); byte digest[] = md5.digest(documentID); System.arraycopy(digest, 0, userKey, 0, 16); for (int k = 16; k < 32; ++k) userKey[k] = 0; for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) digest[j] = (byte) (mkey[j] ^ i); arcfour.prepareARCFOURKey(digest, 0, mkey.length); arcfour.encryptARCFOUR(userKey, 0, 16); } } else { arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(pad, userKey); } }
/** */ private byte[] computeOwnerKey(byte userPad[], byte ownerPad[]) { byte ownerKey[] = new byte[32]; byte digest[] = md5.digest(ownerPad); if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { byte mkey[] = new byte[keyLength / 8]; // only use for the input as many bit as the key consists of for (int k = 0; k < 50; ++k) System.arraycopy(md5.digest(digest), 0, digest, 0, mkey.length); System.arraycopy(userPad, 0, ownerKey, 0, 32); for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) mkey[j] = (byte) (digest[j] ^ i); arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(ownerKey); } } else { arcfour.prepareARCFOURKey(digest, 0, 5); arcfour.encryptARCFOUR(userPad, ownerKey); } return ownerKey; }
/** */ private byte[] computeOwnerKey(byte userPad[], byte ownerPad[]) { byte ownerKey[] = new byte[32]; byte digest[] = md5.digest(ownerPad); if (revision == STANDARD_ENCRYPTION_128 || revision == AES_128) { byte mkey[] = new byte[keyLength / 8]; // only use for the input as many bit as the key consists of for (int k = 0; k < 50; ++k) System.arraycopy(md5.digest(digest), 0, digest, 0, mkey.length); System.arraycopy(userPad, 0, ownerKey, 0, 32); for (int i = 0; i < 20; ++i) { for (int j = 0; j < mkey.length; ++j) mkey[j] = (byte) (digest[j] ^ i); arcfour.prepareARCFOURKey(mkey); arcfour.encryptARCFOUR(ownerKey); } } else { arcfour.prepareARCFOURKey(digest, 0, 5); arcfour.encryptARCFOUR(userPad, ownerKey); } return ownerKey; }
public byte[] update(byte[] b, int off, int len) { if (aes) { if (initiated) return cipher.update(b, off, len); else { int left = Math.min(iv.length - ivptr, len); System.arraycopy(b, off, iv, ivptr, left); off += left; len -= left; ivptr += left; if (ivptr == iv.length) { cipher = new AESCipher(false, key, iv); initiated = true; if (len > 0) return cipher.update(b, off, len); } return null; } } else { byte[] b2 = new byte[len]; arcfour.encryptARCFOUR(b, off, len, b2, 0); return b2; } }
public byte[] update(byte[] b, int off, int len) { if (aes) { if (initiated) return cipher.update(b, off, len); else { int left = Math.min(iv.length - ivptr, len); System.arraycopy(b, off, iv, ivptr, left); off += left; len -= left; ivptr += left; if (ivptr == iv.length) { cipher = new AESCipher(false, key, iv); initiated = true; if (len > 0) return cipher.update(b, off, len); } return null; } } else { byte[] b2 = new byte[len]; arcfour.encryptARCFOUR(b, off, len, b2, 0); return b2; } }