本文整理汇总了Java中org.spongycastle.crypto.Digest.update方法的典型用法代码示例。如果您正苦于以下问题:Java Digest.update方法的具体用法?Java Digest.update怎么用?Java Digest.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongycastle.crypto.Digest
的用法示例。
在下文中一共展示了Digest.update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeTag
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
@Override
public void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber) {
if (tag.length < TAG_LENGTH) throw new IllegalArgumentException();
if (streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
throw new IllegalArgumentException();
// Initialise the PRF
Digest prf = new Blake2sDigest(tagKey.getBytes());
// The output of the PRF must be long enough to use as a tag
int macLength = prf.getDigestSize();
if (macLength < TAG_LENGTH) throw new IllegalStateException();
// The input is the stream number as a 64-bit integer
byte[] input = new byte[INT_64_BYTES];
ByteUtils.writeUint64(streamNumber, input, 0);
prf.update(input, 0, input.length);
byte[] mac = new byte[macLength];
prf.doFinal(mac, 0);
// The output is the first TAG_LENGTH bytes of the MAC
System.arraycopy(mac, 0, tag, 0, TAG_LENGTH);
}
示例2: hash
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
@Override
public byte[] hash(String label, byte[]... inputs) {
byte[] labelBytes = StringUtils.toUtf8(label);
Digest digest = new Blake2sDigest();
byte[] length = new byte[INT_32_BYTES];
ByteUtils.writeUint32(labelBytes.length, length, 0);
digest.update(length, 0, length.length);
digest.update(labelBytes, 0, labelBytes.length);
for (byte[] input : inputs) {
ByteUtils.writeUint32(input.length, length, 0);
digest.update(length, 0, length.length);
digest.update(input, 0, input.length);
}
byte[] output = new byte[digest.getDigestSize()];
digest.doFinal(output, 0);
return output;
}
示例3: macKdf
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
private byte[] macKdf(SecretKey key, byte[]... inputs) {
// Initialise the PRF
Digest prf = new Blake2sDigest(key.getBytes());
// The output of the PRF must be long enough to use as a key
int macLength = prf.getDigestSize();
if (macLength < SecretKey.LENGTH) throw new IllegalStateException();
// Calculate the PRF over the concatenated length-prefixed inputs
byte[] length = new byte[INT_32_BYTES];
for (byte[] input : inputs) {
ByteUtils.writeUint32(input.length, length, 0);
prf.update(length, 0, length.length);
prf.update(input, 0, input.length);
}
byte[] mac = new byte[macLength];
prf.doFinal(mac, 0);
// The output is the first SecretKey.LENGTH bytes of the MAC
if (mac.length == SecretKey.LENGTH) return mac;
byte[] truncated = new byte[SecretKey.LENGTH];
System.arraycopy(mac, 0, truncated, 0, truncated.length);
return truncated;
}
示例4: ripemd160
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
/**
* @param data
* - message to hash
* @return - reipmd160 hash of the message
*/
public static byte[] ripemd160(byte[] data) {
Digest digest = new RIPEMD160Digest();
if (data != null) {
byte[] resBuf = new byte[digest.getDigestSize()];
digest.update(data, 0, data.length);
digest.doFinal(resBuf, 0);
return resBuf;
}
throw new NullPointerException("Can't hash a NULL value");
}
示例5: PseudoRandomImpl
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
PseudoRandomImpl(byte[] seed) {
// Hash the seed to produce a 32-byte key
byte[] key = new byte[32];
Digest digest = new Blake2sDigest();
digest.update(seed, 0, seed.length);
digest.doFinal(key, 0);
// Initialise the stream cipher with an all-zero nonce
byte[] nonce = new byte[8];
cipher.init(true, new ParametersWithIV(new KeyParameter(key), nonce));
}
示例6: ripemd160
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
/**
* @param data - message to hash
* @return - reipmd160 hash of the message
*/
public static byte[] ripemd160(byte[] data) {
Digest digest = new RIPEMD160Digest();
if (data != null) {
byte[] resBuf = new byte[digest.getDigestSize()];
digest.update(data, 0, data.length);
digest.doFinal(resBuf, 0);
return resBuf;
}
throw new NullPointerException("Can't hash a NULL value");
}
示例7: ripemd160
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
/**
* @param data - message to hash
*
* @return - reipmd160 hash of the message
*/
public static byte[] ripemd160(byte[] data) {
Digest digest = new RIPEMD160Digest();
if (data != null) {
byte[] resBuf = new byte[digest.getDigestSize()];
digest.update(data, 0, data.length);
digest.doFinal(resBuf, 0);
return resBuf;
}
throw new NullPointerException("Can't hash a NULL value");
}
示例8: setNewHashValue
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
/**
* Calculate New Hash Value of the current thumbnail.
*
* @param context
* @param rawContact
* @param batchOperation
* @param rawContactId
*/
private static void setNewHashValue(Context context,
BatchOperation batchOperation, long rawContactId) {
// get photo and set new hash and version, because thumbnail will be
// generated from the system.
// Read photo
final ContentResolver resolver = context.getContentResolver();
final Cursor c = resolver.query(DataQuery.CONTENT_URI,
DataQuery.PROJECTION, DataQuery.SELECTION_TYPE,
new String[] { String.valueOf(rawContactId),
Photo.CONTENT_ITEM_TYPE }, null);
try {
while (c.moveToNext()) {
byte[] photo = c.getBlob(DataQuery.COLUMN_PHOTO_IMAGE);
if (photo != null) {
// Generate Hash
Digest digest = new MD5Digest();
byte[] resBuf = new byte[digest.getDigestSize()];
digest.update(photo, 0, photo.length);
digest.doFinal(resBuf, 0);
String hash = Base64.encodeToString(resBuf, Base64.DEFAULT);
int currVersion = c.getInt(DataQuery.COLUMN_VERSION);
int newVersion = currVersion++;
// Set Hash
final ContactOperations contactOp = ContactOperations
.updateExistingContact(rawContactId, true,
batchOperation);
final long id = c.getLong(DataQuery.COLUMN_ID);
final Uri uri = ContentUris.withAppendedId(
Data.CONTENT_URI, id);
contactOp.updatePhotoHash(hash, newVersion, uri);
}
}
} finally {
c.close();
}
}
示例9: stringToHash
import org.spongycastle.crypto.Digest; //导入方法依赖的package包/类
public static String stringToHash(String strToHash, HashAlgorithmTypes hashType) {
Digest hashAlgDigest = DigestFactory.getDigest(hashType);
byte[] output = new byte[hashAlgDigest.getDigestSize()];
byte[] strByteArray = strToHash.getBytes();
hashAlgDigest.update(strByteArray, 0, strByteArray.length);
hashAlgDigest.doFinal(output, 0);
String hexaBaseString = String.format("%064x", new java.math.BigInteger(1, output));
return hexaBaseString;
}