项目作者: AntonGrn

项目描述 :
Symmetric encryption (AES). Symmetric keys distributed using public key encryption (RSA).
高级语言: Java
项目地址: git://github.com/AntonGrn/hybrid-encryption.git
创建时间: 2020-12-20T16:08:27Z
项目社区:https://github.com/AntonGrn/hybrid-encryption

开源协议:

下载


Hybrid Encryption

  • Symmetric encryption (AES with CBC) and message authentication (MAC).
  • Symmetric keys distributed using asymmetric encryption (RSA).
  • Unique keys generated for each new TCP session.

MOTIVATION:

GOAL: Use symmetric cryptography (AES) for client-server communication.

PROBLEM: Distribute symmetric key (AES) in a secure way.

SOLUTION: Distribute symmetric keys (AES) using asymmetric cryptography (RSA).

APPROACH (STEPS):

CLIENT

1. Client requests connection with server (e.g. TCP handshake).

SERVER

2. Server sends public key to client (asymmetric).

CLIENT

3. Client generates AES key, IV and MAC-key (for symmetric encryption).

4. Client encrypts AES key and MAC-key using server’s public key (asymmetric encryption).

5. Client encrypts initial output message (payload) using AES-key and IV (symmetric encryption).

6. Client generates MAC of the payload.

7. Client sends first message to server: AES-key, MAC-key, IV, MAC, message.

  1. ____________________________________________________________________
  2. | | |
  3. | Shared secrets for | Payload: |
  4. | Symmetric cryptography | Initial message |
  5. |_________________________|__________________________________________|
  6. | | | | | |
  7. | AES-key | MAC-key | IV | MAC | Message |
  8. | 128 bit | 128 bit | 128 bit | 128 bit | Variable size |
  9. |____________|____________|____________|____________|________________|
  10. | | | |
  11. | Encrypted: | Plaintext | Encrypted: |
  12. | Asymmetric (RSA) | | Symmetric (AES) |
  13. |_________________________|____________|_____________________________|
  14. [7] Initial message sent from client to server

SERVER

8. Server decrypts AES-key and MAC-key with Server’s private key (asymmetric decryption).

9. Server assigns the symmetric key variables (AES-key, MAC-key, IV).

10. Server decrypts the payload using the symmetric key variables (symmetric decryption).

11. Server verifies MAC.

ENCRYPTED CHANNEL ESTABLISHED (symmetric keys distributed)

12. The continuous communication between client and server will use symmetric cryptography (AES).

  1. ____________________________________________
  2. | | | |
  3. | IV | MAC | Message |
  4. | 128 bit | 128 bit | Variable size |
  5. |____________|____________|__________________|
  6. | | |
  7. | Plaintext | Encrypted: Symmetric (AES) |
  8. |____________|_______________________________|
  9. [12] Encrypted messages after symmetric keys has been distributed
  10. (For CBC: IV can securely be sent in plaintext)

USER GUIDE:

Chronological operations in relation to above notations.

[1-2] SERVER

Preconditions:

  • Client has requested connection with server (e.g. Socket TCP handshake).
  • Each client instance (on server) is mapped to, or holds, unique instance of ServerCryptography.
    • Allows unique encryption credentials (RSA & AES) for each client session.
      ```java
      serverCryptography.generateAsymmericKeyPair()
      byte[] publicKey = serverCryptography.getPublicKeyAsByteArray()

//Write to client: byte[] publicKey

  1. **[3-7] CLIENT**
  2. ```java
  3. //Read from server: byte[] publicKey
  4. clientCryptography.setServersPublicKey(publicKey);
  5. clientCryptography.generateSymmetricKeys();
  6. byte[] encryptedMsg = clientCryptography.createInitialMsg("Hello World!");
  7. //Write to server: byte[] encryptedMsg

[8-11] SERVER

  1. //Read from client: byte[] encryptedMsg
  2. String intialMsg = serverCryptography.processInitialMsg(encryptedMsg);

[12] Symmetric cryptography

AES encrypted traffic may now flow asynchronous in full-duplex, using the following methods:

  1. SERVER
  2. // Read from client: byte[] encryptedInput;
  3. String decrytpedInput = serverCryptography.symmetricDecryption(encryptedInput);
  4. byte[] encryptedOutput = serverCryptography.symmetricEncryption("My message");
  5. // Write to client: byte[] encryptedOutput
  6. [...]
  7. CLIENT
  8. // Read from server: byte[] encryptedInput;
  9. String decrytpedInput = clientCryptography.symmetricDecryption(encryptedInput);
  10. byte[] encryptedOutput = clientCryptography.symmetricEncryption("My message");
  11. // Write to server: byte[] encryptedOutput
  12. [...]

COMPLEMENT WITH:

  • Key store
  • Certificate and digitial signatures