Note about Replacement/Substitution and Shuffling/Reordering
Replacement/Substitution and Shuffling/Reordering are the two techniques EMA uses. They are always used simultaneously on the same block of bytes for both encryption and decryption.
Replacement and Substitution
The Replacement and Substitution processes affect the entire block of bytes and do not move bytes. For example, if we have a block of 100.000 bytes and its respective sub-key, for example, of 200.000 bytes, both the processes replace the values of the source data with the first 100.000 values of the key (source_data XOR key_value) for all 100.000 bytes. If the sub-key only had 10.000 bytes, it will replace the source data values in blocks of 10.000 bytes to reach 100.000 bytes. If the byte block had 100.015 bytes, the first 15 bytes of the key would be used in the last cycle for that block of bytes.
The following example is a piece of the header byte block of 758-byte (highlighted) before the replacement. Data you can see highlighted includes points from 2. to 18. of the section of the page “The pre-encryption data structure -> Only one byte block (first and last byte block)“.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ9b016d8e946b7f64701c8e45b1b3d1dc H = Ž8cª‡Ž3£ILŽ3¢=JŽ3£IL E BUILTIN\Administrators (Alias) C : \ U s e r s \ g u e s t \ e m a \ s r c \ 4 0 0 0 0 0 0 _ J . t x tNT AUTHORITY\SYSTEM:READ_DATA/WRITE_DATA/APPEND_DATA/READ_NAMED_ATTRS/WRITE_NAMED_ATTRS/EXECUTE/DELETE_CHILD/READ_ATTRIBUTES/WRITE_ATTRIBUTES/DELETE/READ_ACL/WRITE_ACL/WRITE_OWNER/SYNCHRONIZE:ALLOW, BUILTIN\Administrators:READ_DATA/WRITE_DATA/APPEND_DATA/READ_NAMED_ATTRS/WRITE_NAMED_ATTRS/EXECUTE/DELETE_CHILD/READ_ATTRIBUTES/WRITE_ATTRIBUTES/DELETE/READ_ACL/WRITE_ACL/WRITE_OWNER/SYNCHRONIZE:ALLOW, BUILTIN\Users:READ_DATA/READ_NAMED_ATTRS/EXECUTE/READ_ATTRIBUTES/READ_ACL/SYNCHRONIZE:ALLOW, \Everyone:READ_DATA/READ_NAMED_ATTRS/EXECUTE/READ_ATTRIBUTES/READ_ACL/SYNCHRONIZE:ALLOWJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
The following block is identical to the previous one, but after replacement. It can be seen that the number of bytes remains exactly the same, but the values have changed (758 bytes):
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHb304201a`1ca43c/d_6adc0/`./`/c55þFþþ;þÿÿŒ6tÿŒ1¡GJÿŒ1 ;HÿŒ1¡GJþþþ Cþþþÿ@SGJRGLZ?bkglgqrp_rmpq&?jg_q'þAþ8þZþSþqþcþpþqþZþeþsþcþqþrþZþcþkþ_þZþqþpþaþZþ2þ.þ.þ.þ.þ.þ.þ]þHþ,þrþvþrLR?SRFMPGRWZQWQRCK8PC?B]B?R?-UPGRC]B?R?-?NNCLB]B?R?-PC?B]L?KCB]?RRPQ-UPGRC]L?KCB]?RRPQ-CVCASRC-BCJCRC]AFGJB-PC?B]?RRPG@SRCQ-UPGRC]?RRPG@SRCQ-BCJCRC-PC?B]?AJ-UPGRC]?AJ-UPGRC]MULCP-QWLAFPMLGXC8?JJMU*@SGJRGLZ?bkglgqrp_rmpq8PC?B]B?R?-UPGRC]B?R?-?NNCLB]B?R?-PC?B]L?KCB]?RRPQ-UPGRC]L?KCB]?RRPQ-CVCASRC-BCJCRC]AFGJB-PC?B]?RRPG@SRCQ-UPGRC]?RRPG@SRCQ-BCJCRC-PC?B]?AJ-UPGRC]?AJ-UPGRC]MULCP-QWLAFPMLGXC8?JJMU*@SGJRGLZSqcpq8PC?B]B?R?-PC?B]L?KCB]?RRPQ-CVCASRC-PC?B]?RRPG@SRCQ-PC?B]?AJ-QWLAFPMLGXC8?JJMU*ZCtcpwmlc8PC?B]B?R?-PC?B]L?KCB]?RRPQ-CVCASRC-PC?B]?RRPG@SRCQ-PC?B]?AJ-QWLAFPMLGXC8?JJMUHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
As can be seen, the replacement range remains 758 bytes. Only values of data origin have been replaced without adding or removing anything.
Shuffling and Reordering
Shuffling and reordering processes act on the entire block of bytes, but in a different way from Replacement and Substitution to achieve the best performance of the encryption and decryption processes. If we tried to achieve complete shuffling within the entire byte block, performance would degrade frighteningly. So the shuffling is limited to a narrow range compared to the size of the byte block used. All data are swapped but the first data value is exchanged with the data value that has the first key value as its index, and so on. It is clear that origin data values with an index greater than 255 are always exchanged with origin data values that have 0 to 255 as their index.
The following example is a piece of the header byte block of 758-byte (highlighted) before the shuffling. Data you can see highlighted includes points from 2. to 18. of the section of the page “The pre-encryption data structure -> Only one byte block (first and last byte block)“.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ11033c5d1cbead55ef6202a2abfab710 H = Ž8BkŽ3£ILŽ3¢=JŽ3£IL E BUILTIN\Administrators (Alias) C : \ U s e r s \ g u e s t \ e m a \ s r c \ 4 0 0 0 0 0 0 _ J . t x tNT AUTHORITY\SYSTEM:READ_DATA/WRITE_DATA/APPEND_DATA/READ_NAMED_ATTRS/WRITE_NAMED_ATTRS/EXECUTE/DELETE_CHILD/READ_ATTRIBUTES/WRITE_ATTRIBUTES/DELETE/READ_ACL/WRITE_ACL/WRITE_OWNER/SYNCHRONIZE:ALLOW, BUILTIN\Administrators:READ_DATA/WRITE_DATA/APPEND_DATA/READ_NAMED_ATTRS/WRITE_NAMED_ATTRS/EXECUTE/DELETE_CHILD/READ_ATTRIBUTES/WRITE_ATTRIBUTES/DELETE/READ_ACL/WRITE_ACL/WRITE_OWNER/SYNCHRONIZE:ALLOW, BUILTIN\Users:READ_DATA/READ_NAMED_ATTRS/EXECUTE/READ_ATTRIBUTES/READ_ACL/SYNCHRONIZE:ALLOW, \Everyone:READ_DATA/READ_NAMED_ATTRS/EXECUTE/READ_ATTRIBUTES/READ_ACL/SYNCHRONIZE:ALLOWJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ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JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
The shuffled data range (2472 bytes) is larger than the replacement range alone (758 bytes) because moves the origin data header outside its border. Trying to decipher it, even in plain text and without first applying value substitution, is not easy without knowing the length or contents of the key.
Note that the ‘J’ character, which is not present in the header, was intentionally inserted to aid in understanding how substitution and shuffling work. Typically, instead of ‘J’ characters, a fixed number of random bytes can be found above the header and the source data can be found below the header.
In each of the examples above, we used two keys with only two values (NUL -> 0 and SOH -> 1) to visually demonstrate the effects of substitution and shuffling.
Blanks you can see in the previous examples really are not printable bytes (chars).
The core of EMA encryption and decryption
- The following simple and short method cryptCore() performs the encryption and the decryption in EMA software
/*
* Copyright 2021-2024 EMA (Encryption by Masking)
* Ema.jar (not static, instantiatable) - Version 1.24.0310.0 (2024.03.10)
* Developer: Stefano Fazzino - Udine (Italy)
* For info and documentation visit https://www.creoart.com
* ***
* 1. EMA is free to use for personal non-profit purposes.
* 2. Public and private companies, universities, colleges, schools, research
* institutes, hospitals, governmental and non-governmental agencies and the
* military are only allowed to test and try it freely. For all other purposes
* they have to ask for permission to use it.
* 3. You may not copy and/or include parts of this software in your own code
* without the explicit permission of the developer.
* 2. Before running the program:
* - check its checksum and if it does not match to the one signed, DO NOT RUN
* - also check the program Ema.jar (not static, instantiatable)
* by sites like https://www.virustotal.com
* 5. For bugs, suggestions, vulnerabilities or anything else send an email:
* i n f o @ c r e o a r t . c o m
* 6. The developer cannot be held responsible in any way for any damages,
* malfunction or any other consequence related to the use of this software.
* 7. If you do not agree, please avoid using this software.
* ***
* ***
* @param sign is 1 or -1 and means encryption or decryption
*/
private static void cryptCore(int sign) {
// 'data[]' pre-encryption data byte array to encrypt and decrypt
// 'key[]' byte array of key values
// 'beginIdx' beginning index of data[] to encrypt or decrypt
// 'endIdx' end index of data[] to encrypt or decrypt
// 'dataLen' length of the data[] byte array
// 'keyLen' total length of the key[] array
// 'subKeyLen' length of sub-keys, half of the keyLen
// 'data_i' single byte of data[] byte array
// 'replacement' index to perform the replacement/substitution
// 'shuffling' index to perform the shuffling/reordering
int beginIdx = (dataLen - 1) * ((1 - sign) / 2);
int endIdx = dataLen - beginIdx;
int subKeyLen = keyLen / 2;
for (int i = beginIdx; i * sign < endIdx; i += sign) {
byte data_i = data[i];
int replacement = i % subKeyLen, shuffling = key[subKeyLen + replacement] & 0xFF;
data[i] = (byte) (data[shuffling] ^ key[replacement]);
data[shuffling] = (byte) (data_i ^ key[replacement]);
}
}
Encrypt a file
The easiest way to encrypt a file while retaining all default settings is as follows:
- setKey(“C:\\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key”);
- fileEncryption(“C:\\Users\\guest\\ema\\src\\4000000.txt”, “C:\\”);
This requires specifying the key file, the origin file and output directory as absolute paths.
Here is the result:
2024.04.27 10:27:35.258 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 10:27:35.259 RUNNING setKeyFilename() ::
2024.04.27 10:27:35.259 SETTING the key
2024.04.27 10:27:35.260 C:\Users\guest\ema\key\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 10:27:35.260 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 10:27:35.260 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 10:27:35.345
2024.04.27 10:27:35.345 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 10:27:35.346 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 10:27:35.346
2024.04.27 10:27:35.347 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 10:27:35.347 RUNNING fileEncryption() ::
2024.04.27 10:27:35.349 SETTING 'C:' as output encrypted files directory
2024.04.27 10:27:35.352 FILE TO ENCRYPT
2024.04.27 10:27:35.352 C:\Users\guest\ema\src\4000000.txt 4.000.000-byte
2024.04.27 10:27:35.353 ..................................................................................................
2024.04.27 10:27:35.353 ENCRYPTION KEY
2024.04.27 10:27:35.353 C:\Users\guest\ema\key\\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 10:27:35.355 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 10:27:35.353 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 10:27:35.355
2024.04.27 10:27:35.355 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 10:27:35.356 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 10:27:35.356 ..................................................................................................
2024.04.27 10:27:35.429 ENCRYPTION SETTINGS
2024.04.27 10:27:35.430 Encryption execution core: ENABLED
2024.04.27 10:27:35.430 Checksum calculation: ENABLED with MD5 algorithm
2024.04.27 10:27:35.431 Encryption details: ENABLED
2024.04.27 10:27:35.431 Use a random name to save the encrypted file: ENABLED
2024.04.27 10:27:35.432 ..................................................................................................
2024.04.27 10:27:35.432 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.27 10:27:35.530 Reading the prepared byte block 0000000001 00088212µs 2.097.152-byte
2024.04.27 10:27:35.652 Calculating MD5 checksum 00007668µs
2024.04.27 10:27:35.667 Encrypting the byte block 0000000001 00013686µs
2024.04.27 10:27:35.670 Writing the encrypted byte block 0000000001 00002451µs 2.097.152-byte
2024.04.27 10:27:35.671 ....
2024.04.27 10:27:35.672 ....
2024.04.27 10:27:35.672 ....
2024.04.27 10:27:35.673 ....
2024.04.27 10:27:35.680 Reading the prepared byte block 0000000002 00001252µs 1.934.556-byte
2024.04.27 10:27:35.681 Calculating MD5 checksum 00004331µs
2024.04.27 10:27:35.689 Encrypting the byte block 0000000002 00007681µs
2024.04.27 10:27:35.692 Writing the encrypted byte block 0000000002 00001559µs 1.934.556-byte
2024.04.27 10:27:35.692 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.27 10:27:35.693 ..................................................................................................
2024.04.27 10:27:35.693 OVERALL TIMES
2024.04.27 10:27:35.695 Time to read 0000000002 byte blocks 00000089ms
2024.04.27 10:27:35.696 Time to calculate the MD5 checksum 00000011ms
2024.04.27 10:27:35.696 Time to complete the encryption 00000021ms
2024.04.27 10:27:35.696 Time to write 0000000002 byte blocks 00000004ms
2024.04.27 10:27:35.697 Total time 00000126ms
2024.04.27 10:27:35.698 ..................................................................................................
2024.04.27 10:27:35.698 SAVING THE ENCRYPTED FILE
2024.04.27 10:27:35.699 C:\1714206455488377100_R2OBN4FwRY4Qp7hoIYdrema8JAKCPX8B.msk 4.031.708-byte
2024.04.27 10:27:35.699 ..................................................................................................
2024.04.27 10:27:35.700 The checksum MD5 was calculated
2024.04.27 10:27:35.700 Encryption performed successfully
2024.04.27 10:27:35.701
2024.04.27 10:27:35.701 FINISHED fileEncryption() ::
We obtain the same result by configuring the necessary paths:
- setKeyFilesDirectory(“C:\\”);
- setOriginFilesDirectory(“C:\\Users\\guest\\ema\\src\\”);
- setEncryptedFilesDirectory(“C:\\”);
- setKey(“1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key”);
- fileEncryption(“4000000.txt”, “”); // note that the output directory is empty
The result:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:31:21.778 RUNNING setKeyFilesDirectory() ::
2024.04.27 08:31:21.782 SETTING 'C:\' as input/output keys files directory
2024.04.27 08:31:21.782
2024.04.27 08:31:21.782 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:31:21.783 RUNNING setOriginFilesDirectory() ::
2024.04.27 08:31:21.783 SETTING 'C:\Users\guest\ema\src\' as origin files directory
2024.04.27 08:31:21.783
2024.04.27 08:31:21.783 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:31:21.784 RUNNING setEncryptedFilesDirectory() ::
2024.04.27 08:31:21.784 SETTING 'C:\' as output encrypted files directory
2024.04.27 08:31:21.784
2024.04.27 08:31:21.784 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:31:21.784 RUNNING setKeyFilename() ::
2024.04.27 08:31:21.785 SETTING the key
2024.04.27 08:31:21.785 C:\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 08:31:21.786 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 08:31:21.785 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 08:31:21.858
2024.04.27 08:31:21.858 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 08:31:21.859 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 08:31:21.859
2024.04.27 08:31:21.859 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:31:21.859 RUNNING fileEncryption() ::
2024.04.27 08:31:21.859 FILE TO ENCRYPT
2024.04.27 08:31:21.859 C:\Users\guest\ema\src\4000000.txt 4.000.000-byte
2024.04.27 08:31:21.859 ..................................................................................................
2024.04.27 08:31:21.860 ENCRYPTION KEY
2024.04.27 08:31:21.860 C:\\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 08:31:21.860 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 08:31:21.860 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 08:31:21.860
2024.04.27 08:31:21.860 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 08:31:21.860 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 08:31:21.861 ..................................................................................................
2024.04.27 08:31:21.896 ENCRYPTION SETTINGS
2024.04.27 08:31:21.897 Encryption execution core: ENABLED
2024.04.27 08:31:21.897 Checksum calculation: ENABLED with MD5 algorithm
2024.04.27 08:31:21.897 Encryption details: ENABLED
2024.04.27 08:31:21.897 Use a random name to save the encrypted file: ENABLED
2024.04.27 08:31:21.897 ..................................................................................................
2024.04.27 08:31:21.897 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.27 08:31:21.909 Reading the prepared byte block 0000000001 00002887µs 2.097.152-byte
2024.04.27 08:31:21.910 Calculating MD5 checksum 00007822µs
2024.04.27 08:31:21.926 Encrypting the byte block 0000000001 00016086µs
2024.04.27 08:31:21.928 Writing the encrypted byte block 0000000001 00001623µs 2.097.152-byte
2024.04.27 08:31:21.929 ....
2024.04.27 08:31:21.929 ....
2024.04.27 08:31:21.929 ....
2024.04.27 08:31:21.929 ....
2024.04.27 08:31:21.936 Reading the prepared byte block 0000000002 00001234µs 1.934.556-byte
2024.04.27 08:31:21.936 Calculating MD5 checksum 00004204µs
2024.04.27 08:31:21.943 Encrypting the byte block 0000000002 00006816µs
2024.04.27 08:31:21.945 Writing the encrypted byte block 0000000002 00001449µs 1.934.556-byte
2024.04.27 08:31:21.945 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.27 08:31:21.946 ..................................................................................................
2024.04.27 08:31:21.946 OVERALL TIMES
2024.04.27 08:31:21.946 Time to read 0000000002 byte blocks 00000004ms
2024.04.27 08:31:21.946 Time to calculate the MD5 checksum 00000012ms
2024.04.27 08:31:21.947 Time to complete the encryption 00000022ms
2024.04.27 08:31:21.947 Time to write 0000000002 byte blocks 00000003ms
2024.04.27 08:31:21.947 Total time 00000042ms
2024.04.27 08:31:21.947 ..................................................................................................
2024.04.27 08:31:21.947 SAVING THE ENCRYPTED FILE
2024.04.27 08:31:21.947 C:\\1714206681980030100_T89wmNjdjWi7P9A4WU9n2BUxRJKeQQpo.msk 4.031.708-byte
2024.04.27 08:31:21.948 ..................................................................................................
2024.04.27 08:31:21.948 The checksum MD5 was calculated
2024.04.27 08:31:21.948 Encryption performed successfully
2024.04.27 08:31:21.948
2024.04.27 08:31:21.948 FINISHED fileEncryption() ::
If you do not specify a key:
- fileEncryption(“4000000.txt”, “”);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:37:08.205 RUNNING disableEncryptionDetails() ::
2024.04.27 08:37:08.206 DISABLING details in encryption stage
2024.04.27 08:37:08.206
2024.04.27 08:37:08.206 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:37:08.206 RUNNING fileEncryption() ::
2024.04.27 08:37:08.206 ERROR: Key NOT SET
If you do not specify a correct path for the origin file:
- setKeyFilesDirectory(“C:\\Users\\guest\\ema\\key\\”);
- setEncryptedFilesDirectory(“C:\\Users\\guest\\ema\\msk\\”);
- setKeyFilename(“1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key”);
- fileEncryption(“4000000.txt”, “”);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:39:14.994 RUNNING setKeyFilesDirectory() ::
2024.04.27 08:39:14.998 SETTING 'C:\Users\guest\ema\key\' as input/output keys files directory
2024.04.27 08:39:14.998
2024.04.27 08:39:14.998 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:39:14.999 RUNNING setEncryptedFilesDirectory() ::
2024.04.27 08:39:14.999 SETTING 'C:\Users\guest\ema\msk\' as output encrypted files directory
2024.04.27 08:39:14.999
2024.04.27 08:39:14.999 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:39:15.000 RUNNING setKeyFilename() ::
2024.04.27 08:39:15.000 SETTING the key
2024.04.27 08:39:15.000 C:\Users\guest\ema\key\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 08:39:15.000 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 08:39:15.000 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 08:39:15.064
2024.04.27 08:39:15.064 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 08:39:15.064 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 08:39:15.064
2024.04.27 08:39:15.064 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:39:15.065 RUNNING fileEncryption() ::
2024.04.27 08:39:15.065 ERROR: '4000000.txt' file NOT FOUND
2024.04.27 08:39:15.065
2024.04.27 08:39:15.065 FINISHED fileEncryption() ::
If you do not want a detailed output log for the fileEncryption() command:
- setKeyFilesDirectory(“C:\\Users\\guest\\ema\\key\\”);
- setEncryptedFilesDirectory(“C:\\Users\\guest\\ema\\msk\\”);
- setOriginFilesDirectory(“C:\\Users\\guest\\ema\\src\\”);
- setKey(“1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key”);
- disableEncryptionDetails();
- fileEncryption(“4000000.txt”, “”);
2024.04.27 08:35:45.960 RUNNING setKeyFilesDirectory() ::
2024.04.27 08:35:45.964 SETTING 'C:\Users\guest\ema\key\' as input/output keys files directory
2024.04.27 08:35:45.965
2024.04.27 08:35:45.965 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:35:45.965 RUNNING setEncryptedFilesDirectory() ::
2024.04.27 08:35:45.966 SETTING 'C:\Users\guest\ema\msk\' as output encrypted files directory
2024.04.27 08:35:45.966
2024.04.27 08:35:45.966 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:35:45.966 RUNNING setOriginFilesDirectory() ::
2024.04.27 08:35:45.967 SETTING 'C:\Users\guest\ema\src\' as origin files directory
2024.04.27 08:35:45.967
2024.04.27 08:35:45.967 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:35:45.967 RUNNING setKeyFilename() ::
2024.04.27 08:35:45.968 SETTING the key
2024.04.27 08:35:45.968 C:\Users\guest\ema\key\1713795503342556300_RiwfKN66ufGX2LV267ld5U8iDLaDLyaR.key 4.194.304-byte
2024.04.27 08:35:45.968 sub-key_1: from index '0' to index '2.097.151'
2024.04.27 08:35:45.968 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.27 08:35:46.037
2024.04.27 08:35:46.037 This key adds 30890 random bytes to the top of pre-encryption data if origin data is a file
2024.04.27 08:35:46.037 and 965 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.27 08:35:46.037
2024.04.27 08:35:46.037 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:35:46.037 RUNNING disableEncryptionDetails() ::
2024.04.27 08:35:46.038 DISABLING details in encryption stage
2024.04.27 08:35:46.038
2024.04.27 08:35:46.038 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.27 08:35:46.038 RUNNING fileEncryption() ::
2024.04.27 08:35:46.038 FILE TO ENCRYPT
2024.04.27 08:35:46.038 C:\Users\guest\ema\src\4000000.txt 4.000.000-byte
2024.04.27 08:35:46.039 ..................................................................................................
2024.04.27 08:35:46.121 SAVING THE ENCRYPTED FILE
2024.04.27 08:35:46.121 C:\Users\guest\ema\msk\1714206946130266400_cOBzmtqrixPkNiWdsWUtb8bCEyac28Ow.msk 4.031.708-byte
2024.04.27 08:35:46.122
2024.04.27 08:35:46.122 FINISHED fileEncryption() ::
Encrypt a byte array
Encrypting a byte array is similar to encrypting a file, but without the need to set filenames or paths. The method requires a byte array with at least one element, unlike file encryption which can also be empty.
Encrypting a byte array produces a ByteResult object consisting of a boolean result and the encrypted byte array is as follow:
- ByteResult encryption = byteArrayEncryption(byteArray);
the encryption result is:
- encryption.getResult(); // boolean
and the encrypted byte array is:
- encryption.getData(); // byte array
Now the decrypted data must be managed by the user. (see Decrypt a byte array)
Example
- String string = “Hello world”;
- byte[] byteArray = string.getBytes();
- setKeyFilename(“1710489295094854777_IPLLUX88fvtd43MRtj10tPTKJqtpRVJg.key”);
- setEncryptionChecksumAlgorithm(3); // SHA-512
- ByteResult encryption = byteArrayEncryption(byteArray);
- ByteResult decryption = byteArrayDecryption(encryption.getData());
- System.out.println();
- for (byte value : decryption.getData()) { System.out.print((char) value); }
2024.04.04 09:22:52.901 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 09:22:52.901 RUNNING setKeyFilename() ::
2024.04.04 09:22:52.902 SETTING the key
2024.04.04 09:22:52.902 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 09:22:52.902 Size = 55.556-byte
2024.04.04 09:22:52.904 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 09:22:52.904 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 09:22:52.906
2024.04.04 09:22:52.907 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 09:22:52.907 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 09:22:52.908
2024.04.04 09:22:52.908 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 09:22:52.909 RUNNING setEncryptionChecksumAlgorithm() ::
2024.04.04 09:22:52.909 SETTING checksum algorithm to 'SHA-256' for encryption
2024.04.04 09:22:52.909
2024.04.04 09:22:52.909 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 09:22:52.910 RUNNING byteArrayEncryption() ::
2024.04.04 09:22:52.913 ENCRYPTING A BYTE ARRAY
2024.04.04 09:22:52.913 Size = 11-byte
2024.04.04 09:22:52.913 ..................................................................................................
2024.04.04 09:22:52.913 ENCRYPTION KEY
2024.04.04 09:22:52.914 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 09:22:52.914 Size = 55.556-byte
2024.04.04 09:22:52.915 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 09:22:52.914 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 09:22:52.915
2024.04.04 09:22:52.915 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 09:22:52.917 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 09:22:52.917 ..................................................................................................
2024.04.04 09:22:52.918 ENCRYPTION SETTINGS
2024.04.04 09:22:52.919 Encryption execution core: ENABLED
2024.04.04 09:22:52.919 Checksum calculation: ENABLED with SHA-256 algorithm
2024.04.04 09:22:52.919 Encryption details: ENABLED
2024.04.04 09:22:52.920 ..................................................................................................
2024.04.04 09:22:52.920 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 09:22:52.920 Reading the prepared byte array 00000569µs 11-byte
2024.04.04 09:22:52.923 Encrypting the byte array 00002680µs
2024.04.04 09:22:52.928 Return the encrypted byte array 00000023µs 65.536-byte
2024.04.04 09:22:52.929 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 09:22:52.929 ..................................................................................................
2024.04.04 09:22:52.929 The checksum SHA-256 was calculated
2024.04.04 09:22:52.930 Encryption performed successfully
2024.04.04 09:22:52.930
2024.04.04 09:22:52.930 FINISHED byteArrayEncryption() ::
2024.04.04 09:22:52.931
2024.04.04 09:22:52.931 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 09:22:52.931 RUNNING byteArrayDecryption() ::
2024.04.04 09:22:52.931 DECRYPTING A BYTE ARRAY
2024.04.04 09:22:52.931 Size = 65.536-byte
2024.04.04 09:22:52.932 ..................................................................................................
2024.04.04 09:22:52.932 DECRYPTION KEY
2024.04.04 09:22:52.932 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 09:22:52.932 Size = 55.556-byte
2024.04.04 09:22:52.933 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 09:22:52.933 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 09:22:52.934 Decrypting the byte array 00000454µs
2024.04.04 09:22:52.934
2024.04.04 09:22:52.935 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 09:22:52.935 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 09:22:52.935 ..................................................................................................
2024.04.04 09:22:52.936 DECRYPTION SETTINGS
2024.04.04 09:22:52.936 Decryption details: ENABLED
2024.04.04 09:22:52.936 ..................................................................................................
2024.04.04 09:22:52.937 STARTING THE CORE EXECUTION IN DECRYPTION MODE
2024.04.04 09:22:52.937 Reading the prepared byte array 00004605µs 65.536-byte
2024.04.04 09:22:52.937 > Checksum SHA-256 algorithm found
2024.04.04 09:22:52.937 Calculating SHA-256 checksum 00000000µs
2024.04.04 09:22:52.938 Return the decrypted byte array 00000005µs 11-byte
2024.04.04 09:22:52.938 FINISHED THE CORE EXECUTION IN DECRYPTION MODE
2024.04.04 09:22:52.939 ..................................................................................................
2024.04.04 09:22:52.939 CHECKSUM SHA-256 was verified and is correct
2024.04.04 09:22:52.939 Decryption performed successfully
2024.04.04 09:22:52.940
2024.04.04 09:22:52.940 FINISHED byteArrayDecryption() ::
2024.04.04 09:22:52.940
2024.04.04 09:22:52.941 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Hello world