private static String encrypt(byte[] key, String plainText) throws CryptoException { try { PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine())); KeyParameter keyParameter = new KeyParameter(key); cipher.init(true, keyParameter); byte[] plainTextBytes = plainText.getBytes(); byte[] cipherTextBytes = new byte[cipher.getOutputSize(plainTextBytes.length)]; int outputLength = cipher.processBytes(plainTextBytes, 0, plainTextBytes.length, cipherTextBytes, 0); cipher.doFinal(cipherTextBytes, outputLength); return ENCODER.encodeToString(cipherTextBytes).trim(); } catch (Exception e) { throw new CryptoException(e); } }
private static String decrypt(byte[] key, String cipherText) throws CryptoException { try { PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine())); cipher.init(false, new KeyParameter(key)); byte[] cipherTextBytes = DECODER.decode(cipherText); byte[] plainTextBytes = new byte[cipher.getOutputSize(cipherTextBytes.length)]; int outputLength = cipher.processBytes(cipherTextBytes, 0, cipherTextBytes.length, plainTextBytes, 0); cipher.doFinal(plainTextBytes, outputLength); int paddingStarts = plainTextBytes.length - 1; for (; paddingStarts >= 0; paddingStarts--) { if (plainTextBytes[paddingStarts] != 0) { break; } } return new String(plainTextBytes, 0, paddingStarts + 1); } catch (Exception e) { throw new CryptoException(e); } }
public ECB() { super(new DESEngine()); } }
public DES9797Alg3() { super(new ISO9797Alg3Mac(new DESEngine())); } }
public PBEWithMD2() { super(new CBCBlockCipher(new DESEngine()), PKCS5S1, MD2, 64, 8); } }
public CBC() { super(new CBCBlockCipher(new DESEngine()), 64); } }
public CMAC() { super(new CMac(new DESEngine())); } }
public PBEWithSHA1() { super(new CBCBlockCipher(new DESEngine()), PKCS5S1, SHA1, 64, 8); } }
public BrokePBEWithSHA1AndDES() { super(new CBCBlockCipher(new DESEngine()), PKCS5S1, SHA1, 64, 64); } }
public PBEWithMD5() { super(new CBCBlockCipher(new DESEngine()), PKCS5S1, MD5, 64, 8); } }
public DESCFB8() { super(new CFBBlockCipherMac(new DESEngine())); } }
public RFC3211() { super(new RFC3211WrapEngine(new DESEngine()), 8); } }
public DES64() { super(new CBCBlockCipherMac(new DESEngine(), 64)); } }
public CBCMAC() { super(new CBCBlockCipherMac(new DESEngine())); } }
public BrokePBEWithMD5AndDES() { super(new CBCBlockCipher(new DESEngine()), PKCS5S1, MD5, 64, 64); } }
@Override public Cipher create() { return new BCBlockCipher(new BufferedBlockCipher(new DESEngine())) { @Override protected CipherParameters createParams(byte[] key) { return new DESedeParameters(key); } }; } });
@Override public Cipher create() { return new BCBlockCipher(new BufferedBlockCipher(new DESEngine())) { @Override protected CipherParameters createParams(byte[] key) { return new DESedeParameters(key); } }; } });
private static PaddedBufferedBlockCipher createCipher(final KeyParameter keyParameter, final boolean forEncryption) { final PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new DESEngine()); cipher.init(forEncryption, keyParameter); return cipher; }
public DES9797Alg3with7816d4() { super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding())); } }
public DES64with7816d4() { super(new CBCBlockCipherMac(new DESEngine(), 64, new ISO7816d4Padding())); } }