本文整理匯總了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();
}
示例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);
}
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}