25#include "org_cipherpack_Cipherpack.h"
26#include "org_cipherpack_Cipherpack_HashUtil.h"
29#include <jau/debug.hpp>
36 jobject jccfg, jobject jenc_pub_keys,
37 jstring jsign_sec_key_fname, jobject jpassphrase,
39 jstring jtarget_path, jstring jsubject,
40 jstring jplaintext_version,
41 jstring jplaintext_version_parent,
43 jstring jplaintext_hash_algo,
44 jstring jdestination_fname)
47 jau::jni::shared_ptr_ref<jau::io::ByteInStream> refSource(env, jsource_feed);
48 jau::jni::shared_ptr_ref<cipherpack::CipherpackListener> refListener(env, cpListener);
51 std::vector<std::string> enc_pub_keys = jau::jni::convert_jlist_string_to_vector(env, jenc_pub_keys);
52 std::string sign_sec_key_fname = jau::jni::from_jstring_to_string(env, jsign_sec_key_fname);
53 jau::io::secure_string passphrase =
nullptr != jpassphrase ? jau::jni::from_jbytebuffer_to_sstring(env, jpassphrase) : jau::io::secure_string();
54 std::string target_path = jau::jni::from_jstring_to_string(env, jtarget_path);
55 std::string subject = jau::jni::from_jstring_to_string(env, jsubject);
56 std::string plaintext_version = jau::jni::from_jstring_to_string(env, jplaintext_version);
57 std::string plaintext_version_parent = jau::jni::from_jstring_to_string(env, jplaintext_version_parent);
58 std::string plaintext_hash_algo = jau::jni::from_jstring_to_string(env, jplaintext_hash_algo);
59 std::string destination_fname =
nullptr != jdestination_fname ? jau::jni::from_jstring_to_string(env, jdestination_fname) :
"";
62 target_path, subject, plaintext_version, plaintext_version_parent,
63 refListener.shared_ptr(), plaintext_hash_algo, destination_fname);
64 jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
76 jobject jsign_pub_keys,
77 jstring jdec_sec_key_fname, jobject jpassphrase,
80 jstring jplaintext_hash_algo,
81 jstring jdestination_fname)
84 jau::jni::shared_ptr_ref<jau::io::ByteInStream> refSource(env, jsource_feed);
85 jau::jni::shared_ptr_ref<cipherpack::CipherpackListener> refListener(env, cpListener);
87 std::vector<std::string> sign_pub_keys = jau::jni::convert_jlist_string_to_vector(env, jsign_pub_keys);
88 std::string dec_sec_key_fname = jau::jni::from_jstring_to_string(env, jdec_sec_key_fname);
89 jau::io::secure_string passphrase =
nullptr != jpassphrase ? jau::jni::from_jbytebuffer_to_sstring(env, jpassphrase) : jau::io::secure_string();
90 std::string plaintext_hash_algo = jau::jni::from_jstring_to_string(env, jplaintext_hash_algo);
91 std::string destination_fname =
nullptr != jdestination_fname ? jau::jni::from_jstring_to_string(env, jdestination_fname) :
"";
94 refListener.shared_ptr(), plaintext_hash_algo, destination_fname);
95 jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
108 jau::jni::shared_ptr_ref<jau::io::ByteInStream> refSource(env, jsource_feed);
109 std::string algo = jau::jni::from_jstring_to_string(env, jalgo);
112 if(
nullptr == hash ) {
115 jbyteArray jhash = jau::jni::convert_bytes_to_jbytearray(env, *hash);
125 std::string algo = jau::jni::from_jstring_to_string(env, jalgo);
126 std::string path_or_uri = jau::jni::from_jstring_to_string(env, jpath_or_uri);
127 const jau::fraction_i64 timeout = (int64_t)jtimeoutMS * 1_ms;
129 if(
nullptr == jbytes_hashed ) {
130 throw jau::IllegalArgumentException(
"bytes_hashed null", E_FILE_LINE);
132 const size_t bh_size = env->GetArrayLength(jbytes_hashed);
134 throw jau::IllegalArgumentException(
"bytes_hashed array size "+
std::to_string(bh_size)+
" < 1", E_FILE_LINE);
136 jau::jni::JNICriticalArray<uint64_t, jlongArray> criticalArray(env);
137 uint64_t * bh_ptr = criticalArray.get(jbytes_hashed, criticalArray.Mode::UPDATE_AND_RELEASE);
138 if(
nullptr == bh_ptr ) {
139 throw jau::InternalError(
"GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
143 if(
nullptr == hash ) {
146 jbyteArray jhash = jau::jni::convert_bytes_to_jbytearray(env, *hash);
jobject Java_org_cipherpack_Cipherpack_checkSignThenDecrypt1(JNIEnv *env, jclass jclazz, jobject jsign_pub_keys, jstring jdec_sec_key_fname, jobject jpassphrase, jobject jsource_feed, jobject cpListener, jstring jplaintext_hash_algo, jstring jdestination_fname)
jbyteArray Java_org_cipherpack_Cipherpack_00024HashUtil_calcImpl2(JNIEnv *env, jclass jclazz, jstring jalgo, jstring jpath_or_uri, jlongArray jbytes_hashed, jlong jtimeoutMS)
jobject Java_org_cipherpack_Cipherpack_encryptThenSignImpl1(JNIEnv *env, jclass jclazz, jobject jccfg, jobject jenc_pub_keys, jstring jsign_sec_key_fname, jobject jpassphrase, jobject jsource_feed, jstring jtarget_path, jstring jsubject, jstring jplaintext_version, jstring jplaintext_version_parent, jobject cpListener, jstring jplaintext_hash_algo, jstring jdestination_fname)
jbyteArray Java_org_cipherpack_Cipherpack_00024HashUtil_calcImpl1(JNIEnv *env, jclass jclazz, jstring jalgo, jobject jsource_feed)
static std::string to_string(const std::vector< uint8_t > &v)
PackHeader encryptThenSign(const CryptoConfig &crypto_cfg, const std::vector< std::string > &enc_pub_keys, const std::string &sign_sec_key_fname, const jau::io::secure_string &passphrase, jau::io::ByteInStream &source, const std::string &target_path, const std::string &subject, const std::string &plaintext_version, const std::string &plaintext_version_parent, CipherpackListenerRef listener, const std::string_view &plaintext_hash_algo, const std::string destination_fname="")
Encrypt then sign the source producing a cipherpack stream passed to the CipherpackListener if opt-in...
PackHeader checkSignThenDecrypt(const std::vector< std::string > &sign_pub_keys, const std::string &dec_sec_key_fname, const jau::io::secure_string &passphrase, jau::io::ByteInStream &source, CipherpackListenerRef listener, const std::string_view &plaintext_hash_algo, const std::string destination_fname="")
Verify signature then decrypt the source passing to the CipherpackListener if opt-in and also optiona...
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.
std::unique_ptr< std::vector< uint8_t > > calc(const std::string_view &algo, jau::io::ByteInStream &source) noexcept
Return the calculated hash value using given algo name and byte input stream.
jobject to_jPackHeader(JNIEnv *env, const cipherpack::PackHeader &ph)
cipherpack::CryptoConfig to_CryptoConfig(JNIEnv *env, jobject jccfg)
CryptoConfig, contains crypto algorithms settings given at encryption wired via the Cipherpack Data S...