Ejemplo n.º 1
0
 /**
  * Descodifica un byte a partir de una imagen mediante el uso de técnicas de esteganografía
  *
  * @return Byte obtenido de la imagen
  */
 private byte decodeByteFromImage() {
   byte currentByte = 0;
   for (int j = 0; j < 8; j++) {
     int index = pixelPath.getNextPathIndex();
     byte mask = (byte) (0x01);
     byte pixelValue = keyBitmap.getByte(index);
     byte bit = (byte) (pixelValue & mask);
     bit = (byte) (bit << 7 - j);
     currentByte = (byte) (currentByte | bit);
   }
   return currentByte;
 }
Ejemplo n.º 2
0
  /**
   * Codifica un byte en una imagen mediante el uso de técnicas de esteganografía
   *
   * @param originalByte Byte que se desea codificar
   */
  private void encodeByteInImage(byte originalByte) {
    for (int j = 0; j < 8; j++) {
      int index = pixelPath.getNextPathIndex();
      byte mask = (byte) (0x80 >> j);
      byte bit = (byte) (originalByte & mask);

      bit = (byte) (bit >> 7 - j);
      byte pixelValue = keyBitmap.getByte(index);
      mask = (byte) 0xFE;
      pixelValue &= mask;
      pixelValue |= bit;
      keyBitmap.setByte(index, pixelValue);
    }
  }
Ejemplo n.º 3
0
  /**
   * Elimina la clave del almacen de claves
   *
   * @throws KeyStoreAccessException
   */
  public void reset() throws KeyStoreAccessException {
    try {
      keyBitmapCollection = new IcoFile(iconPath);
      keyBitmap = keyBitmapCollection.getBitmap(0);

      pixelPath.resetPath();

      removePresencePatternFromImage();

      keyBitmapCollection.saveToDisk(iconPath);
    } catch (IOException e) {
      throw new KeyStoreAccessException();
    } catch (IncorrectImageFormatException e) {
      throw new KeyStoreAccessException();
    }
  }
Ejemplo n.º 4
0
  /**
   * Almacena la clave indicada en la imagen utilizada como almacén
   *
   * @param password Array de bytes que contiene la clave a guardar.
   * @throws KeyStoreAccessException Si se produce algun error al acceder al almacen de claves
   */
  public void saveKey(byte[] password) throws KeyStoreAccessException {
    try {
      keyBitmapCollection = new IcoFile(iconPath);
      keyBitmap = keyBitmapCollection.getBitmap(0);

      pixelPath.resetPath();

      encodePresencePatternInImage();

      byte keyLength = (byte) password.length;

      encodeByteInImage(keyLength);
      encodeByteArrayInImage(password);

      keyBitmapCollection.saveToDisk(iconPath);
    } catch (IOException e) {
      throw new KeyStoreAccessException();
    } catch (IncorrectImageFormatException e) {
      throw new KeyStoreAccessException();
    }
  }
Ejemplo n.º 5
0
  /**
   * Carga la clave almacenada en la imagen que se utiliza como almacen
   *
   * @return Array de Bytes que contiene la clave recuperada
   * @throws KeyNotFoundException Si no se ha encontrado ninguna clave en la imagen
   * @throws KeyStoreAccessException Si se ha producido algun error al acceder al almacen de claves
   */
  public byte[] loadKey() throws KeyStoreAccessException, KeyNotFoundException {
    try {
      keyBitmapCollection = new IcoFile(iconPath);
      keyBitmap = keyBitmapCollection.getBitmap(0);

      pixelPath.resetPath();

      if (testPresencePattern() == false) throw new KeyNotFoundException();

      int keyLength = (decodeByteFromImage() & 0xFF);
      byte byteArrayKey[] = new byte[keyLength];

      for (int i = 0; i < byteArrayKey.length; i++) {
        byte currentByte = decodeByteFromImage();
        byteArrayKey[i] = currentByte;
      }

      return byteArrayKey;
    } catch (IOException e) {
      throw new KeyStoreAccessException();
    } catch (IncorrectImageFormatException e) {
      throw new KeyStoreAccessException();
    }
  }