Example usage for javax.crypto NullCipher NullCipher

List of usage examples for javax.crypto NullCipher NullCipher

Introduction

In this page you can find the example usage for javax.crypto NullCipher NullCipher.

Prototype

public NullCipher() 

Source Link

Document

Creates a NullCipher object.

Usage

From source file:de.codesourcery.eve.apiclient.utils.PasswordCipherProvider.java

@Override
public Cipher createCipher(boolean decrypt) {

    final char[] password = getPassword();

    if (ArrayUtils.isEmpty(password)) {
        log.warn("createCipher(): No password , returning NULL cipher.");
        return new NullCipher();
    }//from   w ww.  j  a  v  a  2  s.  c  o m

    try {

        final int iterations = 20;

        final byte[] salt = new byte[] { (byte) 0xab, (byte) 0xfe, 0x03, 0x47, (byte) 0xde, (byte) 0x99,
                (byte) 0xff, 0x1c };

        final PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iterations);

        final PBEKeySpec spec = new PBEKeySpec(password, salt, iterations);
        final SecretKeyFactory fac = SecretKeyFactory.getInstance("PBEWithMD5andDES");
        final SecretKey secretKey;
        try {
            secretKey = fac.generateSecret(spec);
        } catch (InvalidKeySpecException e) {
            throw e;
        }

        final Cipher cipher = Cipher.getInstance("PBEWithMD5andDES");
        if (decrypt) {
            cipher.init(Cipher.DECRYPT_MODE, secretKey, pbeSpec);
        } else {
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, pbeSpec);
        }
        return cipher;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:at.tfr.securefs.xnio.MessageHandlerImpl.java

private Cipher getCipher(Message message, int mode)
        throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException,
        NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
    if (sksBean == null) {
        return new NullCipher();
    }/*from   ww  w.j a  v  a 2 s.c o m*/
    return sksBean.getCipher(message.getPath(), mode);
}