All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quartzdesk.api.common.security.SecurityUtils Maven / Gradle / Ivy

Go to download

QuartzDesk Public API library required for QuartzDesk Standard and Enterprise edition installations. This library must be placed on the classpath of the Quartz scheduler based application that is managed by QuartzDesk. It is important that this library is loaded by the same classloader that loads the Quartz scheduler API used by the application.

There is a newer version: 5.0.3
Show newest version
/*
 * Copyright (c) 2013-2019 QuartzDesk.com. All Rights Reserved.
 * QuartzDesk.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.quartzdesk.api.common.security;

import com.quartzdesk.api.common.encoding.BASE64Decoder;
import com.quartzdesk.api.common.encoding.BASE64Encoder;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;

/**
 * @version $Id:$
 */
public class SecurityUtils
{
  /**
   * Converts the specified secret key represented as a BASE64 string into a secret key.
   *
   * @param base64 a BASE64 encoded secret key.
   * @param keyAlg the key algorithm.
   * @return the secret key.
   * @throws SecurityException if the specified string is not BASE64 encoded.
   */
  public static SecretKey symmetricKeyFromBASE64( String base64, String keyAlg )
  {
    byte[] keyBytes = BASE64Decoder.decode( base64 );
    return new SecretKeySpec( keyBytes, keyAlg );
  }


  /**
   * Converts the specified key into the BASE64 format.
   *
   * @param key a key.
   * @return the BASE64 key representation.
   */
  public static String symmetricKeyToBASE64( Key key )
  {
    byte[] keyBytes = key.getEncoded();
    return BASE64Encoder.encode( keyBytes );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy