本文整理汇总了Java中org.spongycastle.crypto.Digest类的典型用法代码示例。如果您正苦于以下问题:Java Digest类的具体用法?Java Digest怎么用?Java Digest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Digest类属于org.spongycastle.crypto包,在下文中一共展示了Digest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getDigest
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
public static Digest getDigest(HashAlgorithmTypes shaType) {
if (shaType.equals(HashAlgorithmTypes.SHA_1)) {
return new SHA1Digest();
}
if (shaType.equals(HashAlgorithmTypes.MD_5)) {
return new MD5Digest();
}
if (shaType.equals(HashAlgorithmTypes.SHA_256)) {
return new SHA256Digest();
}
if (shaType.equals(HashAlgorithmTypes.SHA_384)) {
return new SHA384Digest();
}
if (shaType.equals(HashAlgorithmTypes.SHA_512)) {
return new SHA512Digest();
}
return null;
}
示例5: 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");
}
示例6: pbkdf2
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
private byte[] pbkdf2(String password, byte[] salt, int iterations) {
byte[] utf8 = StringUtils.toUtf8(password);
Digest digest = new SHA256Digest();
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
gen.init(utf8, salt, iterations);
int keyLengthInBits = SecretKey.LENGTH * 8;
CipherParameters p = gen.generateDerivedParameters(keyLengthInBits);
return ((KeyParameter) p).getKey();
}
示例7: sampleRunningTime
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
private long sampleRunningTime(int iterations) {
byte[] password = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
byte[] salt = new byte[PBKDF_SALT_BYTES];
int keyLengthInBits = SecretKey.LENGTH * 8;
long start = System.nanoTime();
Digest digest = new SHA256Digest();
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
gen.init(password, salt, iterations);
gen.generateDerivedParameters(keyLengthInBits);
return System.nanoTime() - start;
}
示例8: 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));
}
示例9: 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");
}
示例10: 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");
}
示例11: pbkdf2
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
private byte[] pbkdf2(char[] password, byte[] salt, int iterations) {
byte[] utf8 = toUtf8ByteArray(password);
Digest digest = new SHA384Digest();
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
gen.init(utf8, salt, iterations);
int keyLengthInBits = CIPHER_KEY_BYTES * 8;
CipherParameters p = gen.generateDerivedParameters(keyLengthInBits);
ByteUtils.erase(utf8);
return ((KeyParameter) p).getKey();
}
示例12: sampleRunningTime
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
private long sampleRunningTime(int iterations) {
byte[] password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
byte[] salt = new byte[PBKDF_SALT_BYTES];
int keyLengthInBits = CIPHER_KEY_BYTES * 8;
long start = System.nanoTime();
Digest digest = new SHA384Digest();
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
gen.init(password, salt, iterations);
gen.generateDerivedParameters(keyLengthInBits);
return System.nanoTime() - start;
}
示例13: 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();
}
}
示例14: ConcatKDFBytesGenerator
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
public ConcatKDFBytesGenerator(Digest digest) {
this(1, digest);
}
示例15: getDigest
import org.spongycastle.crypto.Digest; //导入依赖的package包/类
/**
* return the underlying digest.
*/
public Digest getDigest()
{
return digest;
}