本文整理匯總了Java中org.apache.commons.codec.digest.DigestUtils.sha256方法的典型用法代碼示例。如果您正苦於以下問題:Java DigestUtils.sha256方法的具體用法?Java DigestUtils.sha256怎麽用?Java DigestUtils.sha256使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.codec.digest.DigestUtils
的用法示例。
在下文中一共展示了DigestUtils.sha256方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateHash
import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
* Calculates the hash using relevant fields of this type
* @return SHA256-hash as raw bytes
*/
public byte[] calculateHash() {
byte[] hashableData = ArrayUtils.addAll(text.getBytes(), senderHash);
hashableData = ArrayUtils.addAll(hashableData, signature);
hashableData = ArrayUtils.addAll(hashableData, Longs.toByteArray(timestamp));
return DigestUtils.sha256(hashableData);
}
示例2: calculateHash
import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
* Calculates the hash using relevant fields of this type
* @return SHA256-hash as raw bytes
*/
public byte[] calculateHash() {
byte[] hashableData = ArrayUtils.addAll(previousBlockHash, merkleRoot);
hashableData = ArrayUtils.addAll(hashableData, Longs.toByteArray(tries));
hashableData = ArrayUtils.addAll(hashableData, Longs.toByteArray(timestamp));
return DigestUtils.sha256(hashableData);
}
示例3: prepareKeyMap
import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
* Load the private Keymap with the x5t256 thumbprint and the public key
* The map only contains a single key
* @return
* @throws Exception
*/
private Map<String, RSAPublicKey> prepareKeyMap() throws Exception
{
Map<String, RSAPublicKey> keys = new HashMap<>();
Certificate cert = getCertificate();
RSAPublicKey key = (RSAPublicKey)cert.getPublicKey();
byte[] x5tS256 = DigestUtils.sha256(cert.getEncoded());
String b64x5tS256 = org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(x5tS256);
keys.put(b64x5tS256, key);
return keys;
}
示例4: calculateHash
import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
* Calculates the hash using relevant fields of this type
* @return SHA256-hash as raw bytes
*/
private byte[] calculateHash() {
byte[] hashableData = ArrayUtils.addAll(name.getBytes(), publicKey);
return DigestUtils.sha256(hashableData);
}
示例5: getShortkey
import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
* Calculates a text key 8 characters or shorter. Resulting key is URL and JSON safe.
* Current formula is substr(base64(sha256(value)),1,8), but in the future it
* might start returning the actual input string if it is shorter than 8 chars.
*
* @param value - string to be hashed
* @return A string in base 64, 8 chars or shorter.
*/
public static String getShortkey(String value) {
byte[] hash = DigestUtils.sha256(value);
String hashString = IdConverterUtils.convertByteArrayToBase64String(hash,null);
return hashString.substring(0, 8);
}