⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functions.java

📁 java 实现的签名方案
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved. * * Redistribution and use in  source and binary forms, with or without  * modification, are permitted  provided that the following conditions are met: * * 1. Redistributions of  source code must retain the above copyright notice, *    this list of conditions and the following disclaimer. * * 2. Redistributions in  binary form must reproduce the above copyright notice, *    this list of conditions and the following disclaimer in the documentation *    and/or other materials provided with the distribution. *   * 3. The end-user documentation included with the redistribution, if any, must *    include the following acknowledgment: *  *    "This product includes software developed by IAIK of Graz University of *     Technology." *  *    Alternately, this acknowledgment may appear in the software itself, if  *    and wherever such third-party acknowledgments normally appear. *   * 4. The names "Graz University of Technology" and "IAIK of Graz University of *    Technology" must not be used to endorse or promote products derived from  *    this software without prior written permission. *   * 5. Products derived from this software may not be called  *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior  *    written permission of Graz University of Technology. *   *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *  POSSIBILITY  OF SUCH DAMAGE. */package iaik.pkcs.pkcs11.wrapper;import java.math.BigInteger;import java.util.Hashtable;/** * This class contains onyl static methods. It is the place for all functions * that are used by several classes in this package. * * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at> * @author Martin Schl鋐fer <schlaeff@sbox.tugraz.at> */public class Functions {  /**   * Maps mechanism codes as Long to their names as Strings.   */  protected static Hashtable mechansimNames_;  /**   * This table contains the mechanisms that are full encrypt/decrypt   * mechanisms; i.e. mechanisms that support the update functoins.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable fullEncryptDecryptMechanisms_;  /**   * This table contains the mechanisms that are single-operation   * encrypt/decrypt mechanisms; i.e. mechanisms that do not support the update   * functoins.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable singleOperationEncryptDecryptMechanisms_;  /**   * This table contains the mechanisms that are full sign/verify   * mechanisms; i.e. mechanisms that support the update functoins.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable fullSignVerifyMechanisms_;  /**   * This table contains the mechanisms that are single-operation   * sign/verify mechanisms; i.e. mechanisms that do not support the update   * functoins.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable singleOperationSignVerifyMechanisms_;  /**   * This table contains the mechanisms that are sign/verify mechanisms with   * message recovery.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable signVerifyRecoverMechanisms_;  /**   * This table contains the mechanisms that are digest mechanisms.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable digestMechanisms_;  /**   * This table contains the mechanisms that key generation mechanisms; i.e.   * mechanisms for generating symmetric keys.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable keyGenerationMechanisms_;  /**   * This table contains the mechanisms that key-pair generation mechanisms;   * i.e. mechanisms for generating key-pairs.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable keyPairGenerationMechanisms_;  /**   * This table contains the mechanisms that are wrap/unwrap mechanisms.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable wrapUnwrapMechanisms_;  /**   * This table contains the mechanisms that are key derivation mechanisms.   * The Long values of the mechanisms are the keys, and the mechanism   * names are the values.   */  protected static Hashtable keyDerivationMechanisms_;  /**   * For converting numbers to their hex presentation.   */  protected static final char HEX_DIGITS[] = {      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',      'A', 'B', 'C', 'D', 'E', 'F' };  /**   * Converts a long value to a hexadecimal String of length 16. Includes   * leading zeros if necessary.   *   * @param value The long value to be converted.   * @return The hexadecimal string representation of the long value.   */  public static String toFullHexString(long value) {    long currentValue = value;    StringBuffer stringBuffer = new StringBuffer(16);    for(int j = 0; j < 16; j++) {      int currentDigit = (int) currentValue & 0xf;      stringBuffer.append(HEX_DIGITS[currentDigit]);      currentValue >>>= 4;    }    return stringBuffer.reverse().toString();  }  /**   * Converts a int value to a hexadecimal String of length 8. Includes   * leading zeros if necessary.   *   * @param value The int value to be converted.   * @return The hexadecimal string representation of the int value.   */  public static String toFullHexString(int value) {    int currentValue = value;    StringBuffer stringBuffer = new StringBuffer(8);    for(int i = 0; i < 8; i++) {      int currentDigit = currentValue & 0xf;      stringBuffer.append(HEX_DIGITS[currentDigit]);      currentValue >>>= 4;    }    return stringBuffer.reverse().toString();  }  /**   * Converts a long value to a hexadecimal String.   *   * @param value The long value to be converted.   * @return The hexadecimal string representation of the long value.   */  public static String toHexString(long value) {    return Long.toHexString(value);  }  /**   * Converts a byte array to a hexadecimal String. Each byte is presented by   * its two digit hex-code; 0x0A -> "0a", 0x00 -> "00". No leading "0x" is   * included in the result.   *   * @param value the byte array to be converted   * @return the hexadecimal string representation of the byte array   */  public static String toHexString(byte[] value) {    if (value == null) {      return null;    }    StringBuffer buffer = new StringBuffer(2 * value.length);    int          single;    for (int i = 0; i < value.length; i++) {      single = value[i] & 0xFF;      if (single < 0x10) {        buffer.append('0');      }      buffer.append(Integer.toString(single, 16));    }    return buffer.toString();  }  /**   * Converts a long value to a binary String.   *   * @param value the long value to be converted.   * @return the binary string representation of the long value.   */  public static String toBinaryString(long value) {    return Long.toString(value, 2);  }  /**   * Converts a byte array to a binary String.   *   * @param value The byte array to be converted.   * @return The binary string representation of the byte array.   */  public static String toBinaryString(byte[] value) {    BigInteger helpBigInteger = new BigInteger(1, value);    return helpBigInteger.toString(2);  }  /**   * Converts the long value flags to a SlotInfoFlag string.   *   * @param flags The flags to be converted.   * @return The SlotInfoFlag string representation of the flags.   */  public static String slotInfoFlagsToString(long flags) {    StringBuffer buffer = new StringBuffer();    boolean      notFirst = false;    if ((flags & PKCS11Constants.CKF_TOKEN_PRESENT) != 0L) {      buffer.append("CKF_TOKEN_PRESENT");      notFirst = true;    }    if ((flags & PKCS11Constants.CKF_REMOVABLE_DEVICE) != 0L) {      if (notFirst) {        buffer.append(" | ");      }      buffer.append("CKF_TOKEN_PRESENT");      notFirst = true;    }    if ((flags & PKCS11Constants.CKF_HW_SLOT) != 0L) {      if (notFirst) {        buffer.append(" | ");      }      buffer.append("CKF_HW_SLOT");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -