Package br.net.woodstock.rockframework.security.crypt.impl

Source Code of br.net.woodstock.rockframework.security.crypt.impl.SyncCrypterWriter

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security.crypt.impl;

import java.io.IOException;
import java.io.OutputStream;

import javax.crypto.SecretKey;

import br.net.woodstock.rockframework.security.crypt.CrypterException;
import br.net.woodstock.rockframework.security.crypt.CrypterWriter;
import br.net.woodstock.rockframework.util.Assert;
import br.net.woodstock.rockframework.xml.dom.XmlDocument;
import br.net.woodstock.rockframework.xml.dom.XmlElement;

public class SyncCrypterWriter implements CrypterWriter<SyncCrypter> {

  public SyncCrypterWriter() {
    super();
  }

  @Override
  public void write(final SyncCrypter crypter, final OutputStream outputStream) {
    Assert.notNull(crypter, "crypter");
    Assert.notNull(outputStream, "outputStream");
    try {
      SecretKey key = crypter.getSecretKey();
      XmlDocument document = new XmlDocument(CrypterIOHelper.SYNC_CRYPTER_ELEMENT);
      XmlElement root = document.getRoot();
      root.addElement(CrypterIOHelper.KEY_ALGORITHM_ELEMENT).setData(crypter.getAlgorithm());
      CrypterIOHelper.addKey(root, CrypterIOHelper.SECRET_KEY_ELEMENT, key);
      document.write(outputStream);
    } catch (IOException e) {
      throw new CrypterException(e);
    }
  }

}
TOP

Related Classes of br.net.woodstock.rockframework.security.crypt.impl.SyncCrypterWriter

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.