/** * Encrypt the cleartext in byte array format. * @param cleartext The text to be encrypted, in byte form * @param The encrypted ciphertext, in byte form */ public byte[] encrypt( byte[] cleartext ) throws CryptoException { return encrypt(cleartext, 0, cleartext.length); }
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())); } }
} catch ( Exception e ) { try { initDecryptCipher(); } catch (CryptoException err) { bytes = decrypt(bytes); try { ObjectInputStream ois = new ObjectInputStreamWithClassloader(new ByteArrayInputStream(bytes), classLoader);
/** * Decrypt the ciphertext to yield the original cleartext. * @param ciphertext The text to be encrypted, in byte form * @param The decrypted cleartext, in byte form */ public synchronized byte[] decrypt( byte[] ciphertext ) throws CryptoException { try { byte[] result = decryptCipher.doFinal(ciphertext); if (iv != null) { //throw away the first block return Arrays.copyOfRange(result, iv.getIV().length, result.length); } return result; } catch ( Exception e ) { try { initDecryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10006, CorePlugin.Util.gs(CorePlugin.Event.TEIID10006, e.getClass().getName(), 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 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())); } }
} catch ( Exception e ) { try { initDecryptCipher(); } catch (CryptoException err) { bytes = decrypt(bytes); try { ObjectInputStream ois = new ObjectInputStreamWithClassloader(new ByteArrayInputStream(bytes), classLoader);
/** * Decrypt the ciphertext to yield the original cleartext. * @param ciphertext The text to be encrypted, in byte form * @param The decrypted cleartext, in byte form */ public synchronized byte[] decrypt( byte[] ciphertext ) throws CryptoException { try { byte[] result = decryptCipher.doFinal(ciphertext); if (iv != null) { //throw away the first block return Arrays.copyOfRange(result, iv.getIV().length, result.length); } return result; } catch ( Exception e ) { try { initDecryptCipher(); } catch (CryptoException err) { //shouldn't happen } throw new CryptoException(CorePlugin.Event.TEIID10006, CorePlugin.Util.gs(CorePlugin.Event.TEIID10006, e.getClass().getName(), 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(); }
/** * Encrypt the cleartext in byte array format. * @param cleartext The text to be encrypted, in byte form * @param The encrypted ciphertext, in byte form */ public byte[] encrypt( byte[] cleartext ) throws CryptoException { return encrypt(cleartext, 0, cleartext.length); }