List of usage examples for org.apache.commons.codec.digest MessageDigestAlgorithms SHA_512
String SHA_512
To view the source code for org.apache.commons.codec.digest MessageDigestAlgorithms SHA_512.
Click Source Link
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Returns an SHA-512 digest./* w w w . ja v a 2 s. c om*/ * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @return An SHA-512 digest instance. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught, which should never happen because SHA-512 is a * built-in algorithm * @see MessageDigestAlgorithms#SHA_512 */ public static MessageDigest getSha512Digest() { return getDigest(MessageDigestAlgorithms.SHA_512); }
From source file:org.carlspring.strongbox.artifact.generator.NugetPackageGenerator.java
public void createArchive(Nuspec nuspec, File packageFile, String... dependencyList) throws IOException, JAXBException, NoSuchAlgorithmException, NugetFormatException { ZipOutputStream zos = null;/* www.ja v a 2 s . c om*/ LayoutOutputStream layoutOutputStream = null; try { // Make sure the artifact's parent directory exists before writing the model. //noinspection ResultOfMethodCallIgnored packageFile.getParentFile().mkdirs(); FileOutputStream fileOutputStream = new FileOutputStream(packageFile); layoutOutputStream = new LayoutOutputStream(fileOutputStream); layoutOutputStream.addAlgorithm(MessageDigestAlgorithms.SHA_512); layoutOutputStream.setDigestStringifier(this::toBase64); zos = new ZipOutputStream(layoutOutputStream); addNugetNuspecFile(nuspec, zos); createRandomNupkgFile(zos); String id = nuspec.getId(); SemanticVersion version = nuspec.getVersion(); createMetadata(id, version.toString(), zos); createContentType(zos); createRels(id, zos); } finally { ResourceCloser.close(zos, logger); if (layoutOutputStream != null) { generateChecksum(packageFile, layoutOutputStream); } } }
From source file:org.carlspring.strongbox.artifact.generator.NugetPackageGenerator.java
private void generateNuspecFile(Nuspec nuspec) throws IOException, JAXBException, NoSuchAlgorithmException { String packageId = nuspec.getId(); String packageVersion = nuspec.getVersion().toString(); File nuspecFile = new File(getBasedir(), String.format("%s/%s/%s.nuspec", packageId, packageVersion, packageId)); //noinspection ResultOfMethodCallIgnored nuspecFile.getParentFile().mkdirs(); try (FileOutputStream fileOutputStream = new FileOutputStream(nuspecFile)) { LayoutOutputStream layoutOutputStream = new LayoutOutputStream(fileOutputStream); layoutOutputStream.addAlgorithm(MessageDigestAlgorithms.SHA_512); layoutOutputStream.setDigestStringifier(this::toBase64); try {//from ww w.j av a2 s. c om nuspec.saveTo(layoutOutputStream); } finally { layoutOutputStream.close(); } generateChecksum(nuspecFile, layoutOutputStream); } }
From source file:org.carlspring.strongbox.artifact.generator.NugetPackageGenerator.java
private void generateChecksum(File file, LayoutOutputStream layoutOutputStream) throws IOException { String sha512 = layoutOutputStream.getDigestMap().get(MessageDigestAlgorithms.SHA_512); MessageDigestUtils.writeChecksum(file.toPath(), ".sha512", sha512); }
From source file:org.carlspring.strongbox.storage.metadata.nuget.TempNupkgFile.java
/** * Creates a temporary file based on the stream. * * @param inputStream// ww w . java 2 s . c o m * data stream * @param targetFile * file to copy the package to * @return data file * @throws IOException * read / write error * @throws NoSuchAlgorithmException * the system does not have an algorithm for calculating the * value of HASH */ private static String copyDataAndCalculateHash(InputStream inputStream, File targetFile) throws IOException, NoSuchAlgorithmException { MessageDigest messageDigest = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_512); DigestInputStream digestInputStream = new DigestInputStream(inputStream, messageDigest); try (FileOutputStream fileOutputStream = new FileOutputStream(targetFile); ReadableByteChannel src = Channels.newChannel(digestInputStream); FileChannel dest = fileOutputStream.getChannel();) { fastChannelCopy(src, dest); byte[] digest = digestInputStream.getMessageDigest().digest(); return DatatypeConverter.printBase64Binary(digest); } }