static void E ( byte[] key, byte[] data, byte[] e ) throws ShortBufferException { byte[] key7 = new byte[7]; byte[] e8 = new byte[8]; for ( int i = 0; i < key.length / 7; i++ ) { System.arraycopy(key, i * 7, key7, 0, 7); Cipher des = Crypto.getDES(key7); des.update(data, 0, data.length, e8); System.arraycopy(e8, 0, e, i * 8, 8); } }
static void E ( byte[] key, byte[] data, byte[] e ) throws ShortBufferException { byte[] key7 = new byte[7]; byte[] e8 = new byte[8]; for ( int i = 0; i < key.length / 7; i++ ) { System.arraycopy(key, i * 7, key7, 0, 7); Cipher des = Crypto.getDES(key7); des.update(data, 0, data.length, e8); System.arraycopy(e8, 0, e, i * 8, 8); } }
/** * @param key * 7 or 8 byte DES key * @return DES cipher in encryption mode */ public static Cipher getDES ( byte[] key ) { if ( key.length == 7 ) { return getDES(des7to8(key)); } try { Cipher c = Cipher.getInstance("DES/ECB/NoPadding"); c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES")); return c; } catch ( NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e ) { throw new CIFSUnsupportedCryptoException(e); } }
/** * @param key * 7 or 8 byte DES key * @return DES cipher in encryption mode */ public static Cipher getDES ( byte[] key ) { if ( key.length == 7 ) { return getDES(des7to8(key)); } try { Cipher c = Cipher.getInstance("DES/ECB/NoPadding"); c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES")); return c; } catch ( NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e ) { throw new CIFSUnsupportedCryptoException(e); } }