Package com.im.imjutil.cipher

Source Code of com.im.imjutil.cipher.Base64Cipher

package com.im.imjutil.cipher;

import com.im.imjutil.exception.CipherException;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

/**
* Classe responsavel por codificar e decodificar o algoritmo de base64.
* @see {@link Cipher}
*
* @author Felipe Zappala
*/
class Base64Cipher extends Cipher {

  @Override
  public byte[] encrypt(byte[] value) throws CipherException {
    if (value == null || value.length == 0) {
      throw new CipherException("Byte array nulo ou invalido");
    }
    return Base64.encode(value).getBytes();
  }

  @Override
  public byte[] decrypt(byte[] value) throws CipherException {
    if (value == null || value.length == 0) {
      throw new CipherException("Byte array nulo ou invalido");
    }
    return Base64.decode(new String(value));
  }
 
  @Override
  public void setPassword(byte[] password) {
    throw new UnsupportedOperationException("Operacao nao permitida");
  }
 
  @Override
  public byte[] getPassword() {
    throw new UnsupportedOperationException("Operacao nao permitida");
  }
}
TOP

Related Classes of com.im.imjutil.cipher.Base64Cipher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.