public BasicCryptor( Key encryptKey, Key decryptKey, String algorithm, IvParameterSpec iv) throws CryptoException { this.encryptKey = encryptKey; this.cipherAlgorithm = algorithm; this.decryptKey = decryptKey; this.iv = iv; if (iv != null) { randBuffer = new byte[iv.getIV().length]; } initEncryptCipher(); initDecryptCipher(); }
public synchronized byte[] encrypt(byte[] buffer, int offset, int length) throws CryptoException { try { byte[] initBlock = null; if (iv != null) { random.nextBytes(randBuffer); initBlock = encryptCipher.update(randBuffer); } byte[] result = encryptCipher.doFinal(buffer, offset, length); if (initBlock != null) { byte[] newResult = Arrays.copyOf(initBlock, initBlock.length + result.length); System.arraycopy(result, 0, newResult, initBlock.length, result.length); return newResult; } return result; } catch ( Exception e ) { try { initEncryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage())); } }
public synchronized byte[] encrypt(byte[] buffer, int offset, int length) throws CryptoException { try { byte[] initBlock = null; if (iv != null) { random.nextBytes(randBuffer); initBlock = encryptCipher.update(randBuffer); } byte[] result = encryptCipher.doFinal(buffer, offset, length); if (initBlock != null) { byte[] newResult = Arrays.copyOf(initBlock, initBlock.length + result.length); System.arraycopy(result, 0, newResult, initBlock.length, result.length); return newResult; } return result; } catch ( Exception e ) { try { initEncryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage())); } }
public BasicCryptor( Key encryptKey, Key decryptKey, String algorithm, IvParameterSpec iv) throws CryptoException { this.encryptKey = encryptKey; this.cipherAlgorithm = algorithm; this.decryptKey = decryptKey; this.iv = iv; if (iv != null) { randBuffer = new byte[iv.getIV().length]; } initEncryptCipher(); initDecryptCipher(); }
public synchronized Object sealObject(Object object) throws CryptoException { try { if (useSealedObject) { return new SealedObject((Serializable)object, encryptCipher); } AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream(1 << 13); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); oos.close(); return encrypt(baos.getBuffer(), 0, baos.getCount()); } catch ( Exception e ) { try { initEncryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage())); } }
public synchronized Object sealObject(Object object) throws CryptoException { try { if (useSealedObject) { return new SealedObject((Serializable)object, encryptCipher); } AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream(1 << 13); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); oos.close(); return encrypt(baos.getBuffer(), 0, baos.getCount()); } catch ( Exception e ) { try { initEncryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage())); } }