本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例11: toString
import org.bouncycastle.util.encoders.Hex; //导入方法依赖的package包/类
public String toString()
{
return "#"+new String(Hex.encode(string));
}
示例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();
}
}
示例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()));
}