Text or images on a computer are expressed as numbers. See the Data EnCoding page.

Asymmetric encryption is poorly suited for encrypting data larger than the modulus.

Practical encryption is performed in two stages.
  1. The file is encrypted using a block cipher algorithm. A random number is used as the key.
  2. The block cipher key is encrypted using an asymmetric algorithm. The recipient's public key is used for this encryption.

Block Cipher

Simple block encryption
File blocks * 123 234 345 ... 567 ... 789
Encryption key 210 +210+537 +210+870 +210+1314 +210+2535 +210+4200
Encrypted blocks 537 870 1314 1869 3312 5199

The first block of ciphertext contains nonsense that is used to derive the key for the next block.

Simple block decryption
Encrypted blocks 537 870 1314 1869 ... 3312 ... 5199
Encryption key 210 -210-537 -210-870 -210-1314 -210-2535 -210-4200
File blocks 123 234 345 567 789

In reality, addition and subtraction operations are not used. The form below uses an algorithm that hashes the concatenation of the key and the previous ciphertext block. The source text block is added to the hash sum using the XOR operation. But Feistel cipher are often used in block encryption algorithms.




-- Since encryption is performed block-by-block, and the block length is several bytes, the original data must be aligned in a reversible format.



Encryption and decryption
-- Secret Key [ 0, 340282366920938463463374607431768211456 [ the same for both encryption and decryption.
-- Initialization vector [ 0, 340282366920938463463374607431768211456 [ is not secret, but must be unique for each session*.


-- Converting from decimal to Base58 reduces message size by 40%.

The initialization vector will be written unchanged as the first block of ciphertext.


For file transfer, it is more practical to use encrypted ZIP files. When working on the command line (cmd.exe), you can use the -e or -P arguments for encryption. See the help (man).


Subskribita.net