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


Java Hex.encode方法代码示例

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


在下文中一共展示了Hex.encode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: assign

import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
public void assign(Object value, Assignable variable) {
	// Adds the security provider.
	logger.debug("Adding security provider.");
	Security.addProvider(new BouncyCastleProvider());

	logger.debug("Calculating MD5 Hash.");
	// Converts the input to a byte array.
	byte input[] = value.toString().getBytes();

	// Calculates the MD5 digest.
	MD5Digest md5 = new MD5Digest();
	md5.update(input, 0, input.length);

	// Gets the digest size and hashes it.
	byte[] digest = new byte[md5.getDigestSize()];
	md5.doFinal(digest, 0);

	String hash = new String(Hex.encode(digest));
	logger.debug("Setting Hash [{}] into variable [{}].", hash, variable);
	variable.set(hash);
}
 
开发者ID:aurasphere,项目名称:assignables,代码行数:22,代码来源:MD5AssignmentPolicy.java

示例10: main

import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
public static void main(String[] args) {
    byte[] md = new byte[32];
    byte[] msg1 = "abc".getBytes();
    SM3Digest sm3 = new SM3Digest();
    sm3.update(msg1, 0, msg1.length);
    sm3.doFinal(md, 0);
    String s = new String(Hex.encode(md));
    System.out.println(s);
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:10,代码来源:SM3Digest.java

示例11: toString

import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
public String toString()
{
  return "#"+new String(Hex.encode(string));
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:5,代码来源:ASN1OctetString.java

示例12: performEncrypt

import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
private void performEncrypt(byte[] key)
{
    // initialise the cipher with the key bytes, for encryption
    cipher.init(true, new KeyParameter(key));

    /*
     * Create some temporary byte arrays for use in
     * encryption, make them a reasonable size so that
     * we don't spend forever reading small chunks from
     * a file.
     *
     * There is no particular reason for using getBlockSize()
     * to determine the size of the input chunk.  It just
     * was a convenient number for the example.  
     */
    // int inBlockSize = cipher.getBlockSize() * 5;
    int inBlockSize = 47;
    int outBlockSize = cipher.getOutputSize(inBlockSize);

    byte[] inblock = new byte[inBlockSize];
    byte[] outblock = new byte[outBlockSize];

    /* 
     * now, read the file, and output the chunks
     */
    try
    {
        int inL;
        int outL;
        byte[] rv = null;
        while ((inL=in.read(inblock, 0, inBlockSize)) > 0)
        {
            outL = cipher.processBytes(inblock, 0, inL, outblock, 0);
            /*
             * Before we write anything out, we need to make sure
             * that we've got something to write out. 
             */
            if (outL > 0)
            {
                rv = Hex.encode(outblock, 0, outL);
                out.write(rv, 0, rv.length);
                out.write('\n');
            }
        }

        try
        {
            /*
             * Now, process the bytes that are still buffered
             * within the cipher.
             */
            outL = cipher.doFinal(outblock, 0);
            if (outL > 0)
            {
                rv = Hex.encode(outblock, 0, outL);
                out.write(rv, 0, rv.length);
                out.write('\n');
            }
        }
        catch (CryptoException ce)
        {

        }
    }
    catch (IOException ioeread)
    {
        ioeread.printStackTrace();
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:70,代码来源:DESExample.java

示例13: hexEncode

import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
/**
 * Gets the hex encoded artifact.
 * 
 * @return hex encoded artifact
 */
public String hexEncode() {
    return new String(Hex.encode(getArtifactBytes()));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AbstractSAMLArtifact.java


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