24package org.cipherpack;
26import java.io.BufferedWriter;
28import java.io.FileWriter;
29import java.nio.ByteBuffer;
32import org.jau.io.ByteInStream;
33import org.jau.io.ByteInStream_Feed;
34import org.jau.io.PrintUtil;
35import org.jau.util.BasicTypes;
180 final List<String> enc_pub_keys,
181 final String sign_sec_key_fname,
final ByteBuffer passphrase,
182 final ByteInStream source,
183 final String target_path,
final String subject,
184 final String plaintext_version,
185 final String plaintext_version_parent,
187 final String plaintext_hash_algo,
188 final String destination_fname) {
189 return encryptThenSignImpl1(crypto_cfg,
191 sign_sec_key_fname, passphrase,
193 target_path, subject,
195 plaintext_version_parent,
201 final List<String> enc_pub_keys,
202 final String sign_sec_key_fname,
203 final ByteBuffer passphrase,
204 final ByteInStream source,
205 final String target_path,
final String subject,
206 final String plaintext_version,
207 final String plaintext_version_parent,
209 final String plaintext_hash_algo,
210 final String destination_fname);
238 final String dec_sec_key_fname,
final ByteBuffer passphrase,
239 final ByteInStream source,
241 final String plaintext_hash_algo,
242 final String destination_fname) {
243 return checkSignThenDecrypt1(sign_pub_keys,
244 dec_sec_key_fname, passphrase,
250 private static native
PackHeader checkSignThenDecrypt1(
final List<String> sign_pub_keys,
251 final String dec_sec_key_fname,
final ByteBuffer passphrase,
252 final ByteInStream source,
254 final String plaintext_hash_algo,
255 final String destination_fname);
264 return algo.toLowerCase().replace(
"-",
"");
286 public static boolean appendToFile(
final String outFileName,
final String hashedFile,
final String hashAlgo,
final byte[] hashValue) {
287 final String hash_str = BasicTypes.bytesHexString(hashValue, 0, hashValue.length,
true );
288 final String space =
new String(
" ");
289 final String seperator =
new String(
" *");
290 final File file =
new File( outFileName );
292 try( BufferedWriter out =
new BufferedWriter(
new FileWriter(file,
true) ); ) {
296 out.write(seperator);
297 out.write(hashedFile);
300 }
catch (
final Exception ex) {
301 PrintUtil.println(System.err,
"Write hash to file failed: "+outFileName+
": "+ex.getMessage());
302 ex.printStackTrace();
313 public static byte[]
calc(
final String algo,
final ByteInStream source) {
314 return calcImpl1(algo, source);
316 private static native
byte[] calcImpl1(
final String algo,
final ByteInStream source);
327 public static byte[]
calc(
final String algo,
final String path_or_uri,
final long bytes_hashed[],
final long timeoutMS) {
328 return calcImpl2(algo, path_or_uri, bytes_hashed, timeoutMS);
341 public static byte[]
calc(
final String algo,
final String path_or_uri,
final long bytes_hashed[]) {
342 return calcImpl2(algo, path_or_uri, bytes_hashed, 20000);
344 private static native
byte[] calcImpl2(
final String algo,
final String path_or_uri,
final long bytes_hashed[],
final long timeout);
Listener for events occurring while processing a cipherpack message via encryptThenSign() and checkSi...
Hash utility functions to produce a hash file compatible to sha256sum as well as to produce the hash ...
static boolean appendToFile(final String outFileName, final String hashedFile, final String hashAlgo, final byte[] hashValue)
Append the hash signature to the text file out_file.
static byte[] calc(final String algo, final String path_or_uri, final long bytes_hashed[])
Return the calculated hash value using given algo name and the bytes of a single file or all files if...
static byte[] calc(final String algo, final ByteInStream source)
Return the calculated hash value using given algo name and byte input stream.
static byte[] calc(final String algo, final String path_or_uri, final long bytes_hashed[], final long timeoutMS)
Return the calculated hash value using given algo name and the bytes of a single file or all files if...
static String fileSuffix(final String algo)
Return a lower-case file suffix used to store a sha256sum compatible hash signature w/o dot and w/o d...
static PackHeader encryptThenSign(final CryptoConfig crypto_cfg, final List< String > enc_pub_keys, final String sign_sec_key_fname, final ByteBuffer passphrase, final ByteInStream source, final String target_path, final String subject, final String plaintext_version, final String plaintext_version_parent, final CipherpackListener listener, final String plaintext_hash_algo, final String destination_fname)
Encrypt then sign the source producing a cipherpack stream passed to the CipherpackListener if opt-in...
static PackHeader checkSignThenDecrypt(final List< String > sign_pub_keys, final String dec_sec_key_fname, final ByteBuffer passphrase, final ByteInStream source, final CipherpackListener listener, final String plaintext_hash_algo, final String destination_fname)
Verify signature then decrypt the source passing to the CipherpackListener if opt-in and also optiona...
static final int buffer_size
Intermediate copy buffer size of 16384 bytes, usually the 4 x 4096 bytes page-size.
static final String default_hash_algo()
Name of default hash algo for the plaintext message, e.g.
CryptoConfig, contains crypto algorithms settings given at encryption wired via the Cipherpack Data S...