当前位置: 首页>>代码示例>>Java>>正文


Java Hex类代码示例

本文整理汇总了Java中org.bouncycastle.util.encoders.Hex的典型用法代码示例。如果您正苦于以下问题:Java Hex类的具体用法?Java Hex怎么用?Java Hex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Hex类属于org.bouncycastle.util.encoders包,在下文中一共展示了Hex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateDESKey

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Generate des key.
 *
 * @param file the file
 * @throws java.io.IOException Signals that an I/O exception has occurred.
 */
public static void generateDESKey(String file) throws IOException {
    DESedeKeyGenerator kg = new DESedeKeyGenerator();
    KeyGenerationParameters kgp = new KeyGenerationParameters(
            new SecureRandom(),
            DESedeParameters.DES_EDE_KEY_LENGTH * 8);
    kg.init(kgp);
    byte[] key = kg.generateKey();
    BufferedOutputStream keystream =
            new BufferedOutputStream(new FileOutputStream(file));
    byte[] keyhex = Hex.encode(key);
    keystream.write(keyhex, 0, keyhex.length);
    keystream.flush();
    keystream.close();
}
 
开发者ID:oneops,项目名称:oneops,代码行数:21,代码来源:CmsCryptoDES.java

示例2: sign

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Compute the raw signature value over the supplied input.
 * 
 * It is up to the caller to ensure that the specified algorithm ID is consistent with the type of signing key
 * supplied.
 * 
 * @param signingKey the private key with which to compute the signature
 * @param jcaAlgorithmID the Java JCA algorithm ID to use
 * @param input the input over which to compute the signature
 * @return the computed signature value
 * @throws SecurityException thrown if the signature computation results in an error
 */
public static byte[] sign(PrivateKey signingKey, String jcaAlgorithmID, byte[] input) throws SecurityException {
    Logger log = getLogger();
    log.debug("Computing signature over input using private key of type {} and JCA algorithm ID {}", signingKey
            .getAlgorithm(), jcaAlgorithmID);

    try {
        Signature signature = Signature.getInstance(jcaAlgorithmID);
        signature.initSign(signingKey);
        signature.update(input);
        byte[] rawSignature = signature.sign();
        log.debug("Computed signature: {}", new String(Hex.encode(rawSignature)));
        return rawSignature;
    } catch (GeneralSecurityException e) {
        log.error("Error during signature generation", e);
        throw new SecurityException("Error during signature generation", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SigningUtil.java

示例3: createParameters

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
protected X9ECParameters createParameters()
{
    BigInteger c2m163v3n = new BigInteger("03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 16);
    BigInteger c2m163v3h = BigInteger.valueOf(2);

    ECCurve c2m163v3 = new ECCurve.F2m(
        163,
        1, 2, 8,
        new BigInteger("07A526C63D3E25A256A007699F5447E32AE456B50E", 16),
        new BigInteger("03F7061798EB99E238FD6F1BF95B48FEEB4854252B", 16),
        c2m163v3n, c2m163v3h);

    return new X9ECParameters(
        c2m163v3,
        c2m163v3.decodePoint(
            Hex.decode("0202F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB")),
        c2m163v3n, c2m163v3h,
        null);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:X962NamedCurves.java

示例4: fingerprint

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
public static String fingerprint(X509CertificateHolder c)
        throws IOException, CertificateEncodingException {

    byte[] der      = c.getEncoded();
    byte[] sha1     = sha256DigestOf(der);
    byte[] hexBytes = Hex.encode(sha1);
    String hex = new String(hexBytes,
                            "ASCII").toUpperCase();

    final StringBuilder fp = new StringBuilder();
    int                 i  = 0;
    fp.append(hex.substring(i,
                            i + 2));
    while ((i += 2) < hex.length()) {
        fp.append(':');
        fp.append(hex.substring(i,
                                i + 2));
    }
    return fp.toString();
}
 
开发者ID:Zubnix,项目名称:rtcdcjava,代码行数:21,代码来源:RTCCertificate.java

示例5: toString

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * @return a human readable version of the structure
 */
public String toString()
{
    String out = "";
    int tailLength;
    if (tailStack == null)
    {
        tailLength = 0;
    }
    else
    {
        tailLength = tailStack.size();
    }

    for (int i = 0; i < 8 + heightOfTree + tailLength; i++)
    {
        out = out + getStatInt()[i] + " ";
    }
    for (int i = 0; i < 1 + heightOfTree + tailLength; i++)
    {
        out = out + new String(Hex.encode(getStatByte()[i])) + " ";
    }
    out = out + "  " + digestProvider.get().getDigestSize();
    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:28,代码来源:GMSSRootCalc.java

示例6: toString

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * returns a String representation of the treehash instance
 */
public String toString()
{
    String out = "Treehash    : ";
    for (int i = 0; i < 6 + tailLength; i++)
    {
        out = out + this.getStatInt()[i] + " ";
    }
    for (int i = 0; i < 3 + tailLength; i++)
    {
        if (this.getStatByte()[i] != null)
        {
            out = out + new String(Hex.encode((this.getStatByte()[i]))) + " ";
        }
        else
        {
            out = out + "null ";
        }
    }
    out = out + "  " + this.messDigestTree.getDigestSize();
    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:Treehash.java

示例7: toString

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * returns a string representation of the instance
 *
 * @return a string representation of the instance
 */
public String toString()
{
    String out = "" + this.big8 + "  ";
    int[] statInt = new int[9];
    statInt = this.getStatInt();
    byte[][] statByte = new byte[5][mdsize];
    statByte = this.getStatByte();
    for (int i = 0; i < 9; i++)
    {
        out = out + statInt[i] + " ";
    }
    for (int i = 0; i < 5; i++)
    {
        out = out + new String(Hex.encode(statByte[i])) + " ";
    }

    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:GMSSRootSig.java

示例8: toString

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Returns a String representation of the main part of this element
 *
 * @return a String representation of the main part of this element
 */
public String toString()
{
    String out = "";

    for (int i = 0; i < 4; i++)
    {
        out = out + this.getStatInt()[i] + " ";
    }
    out = out + " " + this.mdsize + " " + this.keysize + " "
        + this.two_power_w + " ";

    byte[][] temp = this.getStatByte();
    for (int i = 0; i < 4; i++)
    {
        if (temp[i] != null)
        {
            out = out + new String(Hex.encode(temp[i])) + " ";
        }
        else
        {
            out = out + "null ";
        }
    }
    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:GMSSLeaf.java

示例9: toString

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Returns a human readable form of the GMSS public key
 *
 * @return A human readable form of the GMSS public key
 */
public String toString()
{
    String out = "GMSS public key : "
        + new String(Hex.encode(publicKeyBytes)) + "\n"
        + "Height of Trees: \n";

    for (int i = 0; i < gmssParameterSet.getHeightOfTrees().length; i++)
    {
        out = out + "Layer " + i + " : "
            + gmssParameterSet.getHeightOfTrees()[i]
            + " WinternitzParameter: "
            + gmssParameterSet.getWinternitzParameter()[i] + " K: "
            + gmssParameterSet.getK()[i] + "\n";
    }
    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:BCGMSSPublicKey.java

示例10: getNumber

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
private String getNumber(Number no) {
    if (!hex) {
        return no.toString();
    }

    if (no instanceof Byte) {
        return "0X" + Hex.toHexString(new byte[]{(byte) no});
    } else if (no instanceof Short) {
        return "0X" + Integer.toHexString(Integer.valueOf((short) no));
    } else if (no instanceof Integer) {
        return "0X" + Integer.toHexString((int) no);
    } else if (no instanceof Long) {
        return "0X" + Long.toHexString((long) no);
    } else if (no instanceof Long) {
        return "0X" + Long.toHexString((long) no);
    } else if (no instanceof BigInteger) {
        return "0X" + ((BigInteger) no).toString(16);
    } else {
        return no.toString();
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:22,代码来源:CrlInfoCmd.java

示例11: createParameters

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
protected X9ECParameters createParameters()
{
    // p = (2^128 - 3) / 76439
    BigInteger p = fromHex("DB7C2ABF62E35E668076BEAD208B");
    BigInteger a = fromHex("DB7C2ABF62E35E668076BEAD2088");
    BigInteger b = fromHex("659EF8BA043916EEDE8911702B22");
    byte[] S = Hex.decode("00F50B028E4D696E676875615175290472783FB1");
    BigInteger n = fromHex("DB7C2ABF62E35E7628DFAC6561C5");
    BigInteger h = BigInteger.valueOf(1);

    ECCurve curve = new ECCurve.Fp(p, a, b);
    //ECPoint G = curve.decodePoint(Hex.decode("02"
    //+ "09487239995A5EE76B55F9C2F098"));
    ECPoint G = curve.decodePoint(Hex.decode("04"
        + "09487239995A5EE76B55F9C2F098"
        + "A89CE5AF8724C0A23E0E0FF77500"));

    return new X9ECParameters(curve, G, n, h, S);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:SECNamedCurves.java

示例12: deletePkcs11Entry

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
private static boolean deletePkcs11Entry(File dir, byte[] objectId) {
    String hextId = Hex.toHexString(objectId);
    File infoFile = new File(dir, hextId + INFO_FILE_SUFFIX);
    boolean b1 = true;
    if (infoFile.exists()) {
        b1 = infoFile.delete();
    }

    File valueFile = new File(dir, hextId + VALUE_FILE_SUFFIX);
    boolean b2 = true;
    if (valueFile.exists()) {
        b2 = valueFile.delete();
    }

    return b1 || b2;
}
 
开发者ID:xipki,项目名称:xitk,代码行数:17,代码来源:EmulatorP11Slot.java

示例13: signMAC

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Compute the Message Authentication Code (MAC) value over the supplied input.
 * 
 * It is up to the caller to ensure that the specified algorithm ID is consistent with the type of signing key
 * supplied.
 * 
 * @param signingKey the key with which to compute the MAC
 * @param jcaAlgorithmID the Java JCA algorithm ID to use
 * @param input the input over which to compute the MAC
 * @return the computed MAC value
 * @throws SecurityException thrown if the MAC computation results in an error
 */
public static byte[] signMAC(Key signingKey, String jcaAlgorithmID, byte[] input) throws SecurityException {
    Logger log = getLogger();
    log.debug("Computing MAC over input using key of type {} and JCA algorithm ID {}", signingKey.getAlgorithm(),
            jcaAlgorithmID);

    try {
        Mac mac = Mac.getInstance(jcaAlgorithmID);
        mac.init(signingKey);
        mac.update(input);
        byte[] rawMAC = mac.doFinal();
        log.debug("Computed MAC: {}", new String(Hex.encode(rawMAC)));
        return rawMAC;
    } catch (GeneralSecurityException e) {
        log.error("Error during MAC generation", e);
        throw new SecurityException("Error during MAC generation", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SigningUtil.java

示例14: sha3

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
public static String sha3(String key) {
	DigestKeccak md = new DigestKeccak(512);
	try {
		md.update(key.getBytes("UTF-8"));
	}catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	byte[] digest=md.digest();
	return Hex.toHexString(digest);
}
 
开发者ID:okfarm09,项目名称:JYLAND,代码行数:11,代码来源:Sha.java

示例15: encrypt

import org.bouncycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Encrypt.
 *
 * @param instr the instr
 * @return the string
 * @throws java.security.GeneralSecurityException the general security exception
 */
@Override
public String encrypt(String instr) throws GeneralSecurityException {
    long t1 = System.currentTimeMillis();
    byte[] in = instr.getBytes();
    PaddedBufferedBlockCipher encryptor = new PaddedBufferedBlockCipher(
            new CBCBlockCipher(new DESedeEngine()));
    encryptor.init(true, keyParameter);
    byte[] cipherText = new byte[encryptor.getOutputSize(in.length)];
    int outputLen = encryptor.processBytes(in, 0, in.length, cipherText, 0);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        encryptor.doFinal(cipherText, outputLen);
        Hex.encode(cipherText, os);
    } catch (Exception e) {
        e.printStackTrace();
        throw new GeneralSecurityException(e);
    }
    long t2 = System.currentTimeMillis();
    logger.debug("Time taken to encrypt(millis) :" + (t2 - t1));
    return ENC_PREFIX + os.toString();
}
 
开发者ID:oneops,项目名称:oneops,代码行数:29,代码来源:CmsCryptoDES.java


注:本文中的org.bouncycastle.util.encoders.Hex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。