Cipherpack v1.2.0-dirty
A Cryprographic Stream Processor
CryptoConfig.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24package org.cipherpack;
25
26/**
27 * CryptoConfig, contains crypto algorithms settings given at encryption wired via the @ref cipherpack_stream "Cipherpack Data Stream",
28 * hence received and used at decryption if matching keys are available.
29 *
30 * @see @ref cipherpack_overview "Cipherpack Overview"
31 * @see @ref cipherpack_stream "Cipherpack Data Stream"
32 */
33public class CryptoConfig {
34 public final String pk_type;
35 public final String pk_fingerprt_hash_algo;
36 public final String pk_enc_padding_algo;
37 public final String pk_enc_hash_algo;
38 public final String pk_sign_algo;
39 public final String sym_enc_algo;
40 public final long sym_enc_nonce_bytes;
41
42 public CryptoConfig() {
43 this.pk_type = "";
44 this.pk_fingerprt_hash_algo = "";
45 this.pk_enc_padding_algo = "";
46 this.pk_enc_hash_algo = "";
47 this.pk_sign_algo = "";
48 this.sym_enc_algo = "";
49 this.sym_enc_nonce_bytes = 0;
50 }
51 public CryptoConfig(final String pk_type_,
52 final String pk_fingerprt_hash_algo_,
53 final String pk_enc_padding_algo_,
54 final String pk_enc_hash_algo_,
55 final String pk_sign_algo_,
56 final String sym_enc_algo_,
57 final long sym_enc_nonce_bytes_) {
58 this.pk_type = pk_type_;
59 this.pk_fingerprt_hash_algo = pk_fingerprt_hash_algo_;
60 this.pk_enc_padding_algo = pk_enc_padding_algo_;
61 this.pk_enc_hash_algo = pk_enc_hash_algo_;
62 this.pk_sign_algo = pk_sign_algo_;
63 this.sym_enc_algo = sym_enc_algo_;
64 this.sym_enc_nonce_bytes = sym_enc_nonce_bytes_;
65 }
66
67 public final boolean valid() {
68 return !pk_type.isEmpty() &&
69 !pk_fingerprt_hash_algo.isEmpty() &&
70 !pk_enc_padding_algo.isEmpty() &&
71 !pk_enc_hash_algo.isEmpty() &&
72 !pk_sign_algo.isEmpty() &&
73 !sym_enc_algo.isEmpty() &&
75
76 }
77
78 @Override
79 public final String toString() {
80 return "CCfg[pk[type '"+pk_type+"', fingerprt_hash '"+pk_fingerprt_hash_algo+"', enc_padding '"+pk_enc_padding_algo+
81 "', enc_hash '"+pk_enc_hash_algo+"', sign '"+pk_sign_algo+
82 "'], sym['"+sym_enc_algo+"', nonce "+sym_enc_nonce_bytes+" byte]]";
83 }
84
85 private static String default_pk_type = "RSA";
86 private static String default_pk_fingerprt_hash_algo = "SHA-256";
87 private static String default_pk_enc_padding_algo = "OAEP"; // or "EME1"
88 private static String default_pk_enc_hash_algo = "SHA-256";
89 private static String default_pk_sign_algo = "EMSA1(SHA-256)";
90 private static String default_sym_enc_mac_algo = "ChaCha20Poly1305"; // or "AES-256/GCM"
91 private static long ChaCha_Nonce_BitSize = 96;
92
93 /**
94 * Returns default CryptoConfig.
95 *
96 * - Public-Key type is {@code RSA}.
97 * - Public key fingerprint hash algorithm is {@code SHA-256}.
98 * - Public-Key padding algorithm is {@code OAEP}.
99 * - Public-Key hash algorithm is {@code SHA-256}.
100 * - Public-Key hash algorithm is {@code EMSA1(SHA-256)}.
101 * - Symmetric Authenticated Encryption with Additional Data (AEAD) encryption+MAC cipher algo is {@code ChaCha20Poly1305}.
102 * - Symmetric AEAD ChaCha Nonce size 96 bit for one message per symmetric-key. Sizes are usually: 64-bit classic, 96-bit IETF, 192-bit big.
103 */
104 public static CryptoConfig getDefault() {
105 return new CryptoConfig (
106 default_pk_type, default_pk_fingerprt_hash_algo,
107 default_pk_enc_padding_algo, default_pk_enc_hash_algo,
108 default_pk_sign_algo, default_sym_enc_mac_algo, ChaCha_Nonce_BitSize/8
109 );
110 }
111}
CryptoConfig, contains crypto algorithms settings given at encryption wired via the Cipherpack Data S...
CryptoConfig(final String pk_type_, final String pk_fingerprt_hash_algo_, final String pk_enc_padding_algo_, final String pk_enc_hash_algo_, final String pk_sign_algo_, final String sym_enc_algo_, final long sym_enc_nonce_bytes_)
static CryptoConfig getDefault()
Returns default CryptoConfig.
final String pk_fingerprt_hash_algo