use of java.security.DigestOutputStream in project j2objc by google.
the class DigestOutputStreamTest method test_getMessageDigest.
/**
* java.security.DigestOutputStream#getMessageDigest()
*/
public void test_getMessageDigest() {
MessageDigest digest = new MyMessageDigest1();
OutputStream out = new MyOutputStream();
// non-null parameter
DigestOutputStream dos = new DigestOutputStream(out, digest);
assertSame(digest, dos.getMessageDigest());
// null parameter
dos = new DigestOutputStream(out, null);
assertNull("getMessageDigest should have returned null", dos.getMessageDigest());
}
use of java.security.DigestOutputStream in project ranger by apache.
the class RangerKeyStore method engineStore.
@Override
public void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException {
if (logger.isDebugEnabled()) {
logger.debug("==> RangerKeyStore.engineStore()");
}
synchronized (deltaEntries) {
if (keyVaultEnabled) {
for (Entry<String, Object> entry : deltaEntries.entrySet()) {
Long creationDate = ((SecretKeyByteEntry) entry.getValue()).date.getTime();
SecretKeyByteEntry secretSecureKey = (SecretKeyByteEntry) entry.getValue();
XXRangerKeyStore xxRangerKeyStore = mapObjectToEntity(entry.getKey(), creationDate, secretSecureKey.key, secretSecureKey.cipher_field, secretSecureKey.bit_length, secretSecureKey.description, secretSecureKey.version, secretSecureKey.attributes);
dbOperationStore(xxRangerKeyStore);
}
} else {
// password is mandatory when storing
if (password == null) {
throw new IllegalArgumentException("Ranger Master Key can't be null");
}
MessageDigest md = getKeyedMessageDigest(password);
byte[] digest = md.digest();
for (Entry<String, Object> entry : deltaEntries.entrySet()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(new DigestOutputStream(baos, md));
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(dos);
oos.writeObject(((SecretKeyEntry) entry.getValue()).sealedKey);
dos.write(digest);
dos.flush();
Long creationDate = ((SecretKeyEntry) entry.getValue()).date.getTime();
SecretKeyEntry secretKey = (SecretKeyEntry) entry.getValue();
XXRangerKeyStore xxRangerKeyStore = mapObjectToEntity(entry.getKey(), creationDate, baos.toByteArray(), secretKey.cipher_field, secretKey.bit_length, secretKey.description, secretKey.version, secretKey.attributes);
dbOperationStore(xxRangerKeyStore);
} finally {
if (oos != null) {
oos.close();
} else {
dos.close();
}
}
}
}
clearDeltaEntires();
}
}
use of java.security.DigestOutputStream in project rskj by rsksmart.
the class MapSnapshotTest method composeByteArray.
private static byte[] composeByteArray(OutputStreamConsumer consumer) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
DigestOutputStream digestOutput = new DigestOutputStream(outputStream, HashUtil.makeMessageDigest());
DataOutputStream dataOutput = new DataOutputStream(digestOutput);
consumer.accept(dataOutput);
byte[] digest = digestOutput.getMessageDigest().digest();
dataOutput.writeInt(digest.length);
dataOutput.write(digest);
} catch (IOException e) {
throw new RuntimeException(e);
}
return outputStream.toByteArray();
}
use of java.security.DigestOutputStream in project rskj by rsksmart.
the class MapSnapshotTest method writeSnapshot_WhenWrite_ShouldPopulateOutputStream.
@Test
public void writeSnapshot_WhenWrite_ShouldPopulateOutputStream() throws IOException {
byte[] key = new byte[] { 0, 1, 2, 3, 4 };
byte[] value = new byte[] { 5, 6, 7, 8, 9 };
Map<ByteArrayWrapper, byte[]> outMap = new HashMap<>();
outMap.put(ByteUtil.wrap(key), value);
ByteArrayOutputStream expectedOutputStream = new ByteArrayOutputStream();
DigestOutputStream digestOutput = new DigestOutputStream(expectedOutputStream, HashUtil.makeMessageDigest());
DataOutputStream dataOutputStream = new DataOutputStream(digestOutput);
dataOutputStream.writeInt(1);
dataOutputStream.writeInt(key.length);
dataOutputStream.write(key);
dataOutputStream.writeInt(value.length);
dataOutputStream.write(value);
byte[] digest = digestOutput.getMessageDigest().digest();
dataOutputStream.writeInt(digest.length);
dataOutputStream.write(digest);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
MapSnapshot.Out outSnapshot = new MapSnapshot.Out(outputStream);
outSnapshot.write(outMap);
assertArrayEquals(expectedOutputStream.toByteArray(), outputStream.toByteArray());
}
use of java.security.DigestOutputStream in project gocd by gocd.
the class PluginsZip method create.
public void create() {
checkFilesAccessibility(bundledPlugins, externalPlugins);
reset();
MessageDigest md5Digest = DigestUtils.getMd5Digest();
try (ZipOutputStream zos = new ZipOutputStream(new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(destZipFile)), md5Digest))) {
for (GoPluginBundleDescriptor agentPlugins : agentPlugins()) {
String zipEntryPrefix = "external/";
if (agentPlugins.isBundledPlugin()) {
zipEntryPrefix = "bundled/";
}
zos.putNextEntry(new ZipEntry(zipEntryPrefix + new File(agentPlugins.bundleJARFileLocation()).getName()));
Files.copy(new File(agentPlugins.bundleJARFileLocation()).toPath(), zos);
zos.closeEntry();
}
} catch (Exception e) {
LOG.error("Could not create zip of plugins for agent to download.", e);
}
md5DigestOfPlugins = Hex.encodeHexString(md5Digest.digest());
}
Aggregations