Java Examples for org.spongycastle.crypto.Digest
The following java examples will help you to understand the usage of org.spongycastle.crypto.Digest. These source code samples are taken from different open source projects.
Example 1
| Project: oobd-master File: JDKKeyStore.java View source code |
public void engineLoad(InputStream stream, char[] password) throws IOException {
table.clear();
if (// just initialising
stream == null) {
return;
}
DataInputStream dIn = new DataInputStream(stream);
int version = dIn.readInt();
if (version != STORE_VERSION) {
if (version != 0 && version != 1) {
throw new IOException("Wrong version of key store.");
}
}
byte[] salt = new byte[dIn.readInt()];
if (salt.length != STORE_SALT_SIZE) {
throw new IOException("Key store corrupted.");
}
dIn.readFully(salt);
int iterationCount = dIn.readInt();
if ((iterationCount < 0) || (iterationCount > 4 * MIN_ITERATIONS)) {
throw new IOException("Key store corrupted.");
}
String cipherAlg;
if (version == 0) {
cipherAlg = "Old" + STORE_CIPHER;
} else {
cipherAlg = STORE_CIPHER;
}
Cipher cipher = this.makePBECipher(cipherAlg, Cipher.DECRYPT_MODE, password, salt, iterationCount);
CipherInputStream cIn = new CipherInputStream(dIn, cipher);
Digest dig = new SHA1Digest();
DigestInputStream dgIn = new DigestInputStream(cIn, dig);
this.loadStore(dgIn);
// Finalise our digest calculation
byte[] hash = new byte[dig.getDigestSize()];
dig.doFinal(hash, 0);
// TODO Should this actually be reading the remainder of the stream?
// Read the original digest from the stream
byte[] oldHash = new byte[dig.getDigestSize()];
Streams.readFully(cIn, oldHash);
if (!Arrays.constantTimeAreEqual(hash, oldHash)) {
table.clear();
throw new IOException("KeyStore integrity check failed.");
}
}Example 2
| Project: android-keystore-master File: Crypto.java View source code |
public static String encryptRsaOaep(String plaintext, String keyAlias) {
try {
AndroidRsaEngine rsa = new AndroidRsaEngine(keyAlias, false);
Digest digest = new SHA512Digest();
Digest mgf1digest = new SHA512Digest();
OAEPEncoding oaep = new OAEPEncoding(rsa, digest, mgf1digest, null);
oaep.init(true, null);
byte[] plainBytes = plaintext.getBytes("UTF-8");
byte[] cipherText = oaep.processBlock(plainBytes, 0, plainBytes.length);
return toBase64(cipherText);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e);
}
}Example 3
| Project: ethereumj-master File: MGF1BytesGeneratorExt.java View source code |
public Digest getDigest() {
return this.digest;
}