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

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

/*
* 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.security.Key;

import br.net.woodstock.rockframework.utils.Base64Utils;
import br.net.woodstock.rockframework.xml.dom.XmlElement;

abstract class CrypterIOHelper {

  public static final String  KEY_ALGORITHM_ELEMENT  = "key-algorithm";

  public static final String  SECRET_KEY_ELEMENT    = "secret-key";

  public static final String  PUBLIC_KEY_ELEMENT    = "public-key";

  public static final String  PRIVATE_KEY_ELEMENT    = "private-key";

  public static final String  ASYNC_CRYPTER_ELEMENT  = "async-crypter";

  public static final String  SYNC_CRYPTER_ELEMENT  = "sync-crypter";

  private CrypterIOHelper() {
    //
  }

  public static void addKey(final XmlElement parent, final String name, final Key key) {
    byte[] base64 = Base64Utils.toBase64(key.getEncoded());
    String str = new String(base64);
    XmlElement e = parent.addElement(name);
    e.setData(str);
  }

  public static byte[] getKey(final XmlElement parent, final String name) {
    XmlElement e = parent.getElement(name);
    if (e != null) {
      String str = e.getData();
      byte[] base64 = str.getBytes();
      byte[] encoded = Base64Utils.fromBase64(base64);
      return encoded;
    }
    return null;
  }

  public static String getElementData(final XmlElement parent, final String name) {
    XmlElement e = parent.getElement(name);
    if (e != null) {
      String str = e.getData();
      return str;
    }
    return null;
  }

}
TOP

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

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.