|
| 1 | +## Encryption functions overview |
| 2 | + |
| 3 | +This document provides comprehensive information about encryption functions that transform plaintext data into encrypted ciphertext. These functions provide robust security measures that require proper documentation to implement and maintain effectively. This guide offers the necessary information for successful implementation. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Overview of capabilities |
| 8 | + |
| 9 | +This documentation will guide you through: |
| 10 | + |
| 11 | +* Implementing data encryption protocols |
| 12 | + |
| 13 | +* Executing data decryption procedures |
| 14 | + |
| 15 | +* Implementing digital signature authentication |
| 16 | + |
| 17 | +* Avoiding common implementation pitfalls |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +First, let's review some key terms you'll encounter throughout this guide. |
| 23 | + |
| 24 | + |
| 25 | +## Glossary of terms |
| 26 | + |
| 27 | +Here's a quick reference guide to the cryptographic terms used in this document: |
| 28 | + |
| 29 | +* **Encryption**: The process of converting readable data into a coded format that can only be decoded with the correct key. |
| 30 | + |
| 31 | +* **Decryption**: The reverse process of encryption, converting coded data back to its original readable form. |
| 32 | + |
| 33 | +* **Symmetric Encryption**: A type of encryption where the same key is used for both encryption and decryption, like a single key that locks and unlocks the same door. |
| 34 | + |
| 35 | +* **Asymmetric Encryption**: A type of encryption that uses a pair of keys - a public key for encryption and a private key for decryption, or vice versa. |
| 36 | + |
| 37 | +* **RSA** (Rivest-Shamir-Adleman): One of the most widely used asymmetric encryption algorithms, named after its creators. |
| 38 | + |
| 39 | +* **DSA** (Digital Signature Algorithm): An algorithm specifically designed for creating digital signatures. |
| 40 | + |
| 41 | +* **DH** (Diffie-Hellman): A method that allows two parties to establish a shared secret key over an insecure channel without sharing any secret information beforehand. |
| 42 | + |
| 43 | +* **Digest/Hash**: A fixed-size string of bytes generated from input data of any size, functioning like a digital fingerprint of the data. |
| 44 | + |
| 45 | +* **Digital Signature**: An electronic equivalent of a handwritten signature that uses asymmetric cryptography to verify authenticity. |
| 46 | + |
| 47 | +* **Padding**: Additional data added to a message before encryption to enhance security and prevent pattern analysis. |
| 48 | + |
| 49 | +* **PEM Format**: Privacy Enhanced Mail format, a common format for storing and sending cryptographic keys, certificates, and other data. |
| 50 | + |
| 51 | +Now, let's examine common implementation challenges in encryption systems. |
| 52 | + |
| 53 | +## Implementation challenges |
| 54 | + |
| 55 | +> ⚠️ **Common encryption mistakes** |
| 56 | +> |
| 57 | +> Key management is a critical aspect of encryption systems that requires rigorous planning and careful implementation. |
| 58 | +> |
| 59 | +
|
| 60 | +Here are the most common implementation issues: |
| 61 | + |
| 62 | +* Key loss: When decryption keys are lost, data becomes permanently inaccessible, even to authorized personnel. |
| 63 | + |
| 64 | +*Algorithm-key mismatch: Using incompatible keys and algorithms results in decryption failures. |
| 65 | + |
| 66 | +* Exceeding size limitations: Attempting to encrypt data larger than algorithm constraints can cause failures in both encryption and decryption processes. |
| 67 | + |
| 68 | +* Insufficient documentation: Failing to properly document the encryption process and key management procedures can lead to system failures. |
| 69 | + |
| 70 | +## Version updates |
| 71 | + |
| 72 | +Percona Server for MySQL 8.0.41 introduces several important new features that enhance security capabilities while requiring careful implementation. |
| 73 | + |
| 74 | +### Padding options for RSA encryption |
| 75 | + |
| 76 | +| Padding type | Security level | Application | Characteristics | |
| 77 | +|--------------|----------------|------------------------|------------------------------------------------| |
| 78 | +| `pkcs1` | Basic | Legacy compatibility | Standard protection with known limitations | |
| 79 | +| `oaep` | High | Modern applications | Enhanced protection with additional security layers | |
| 80 | +| `no` | None | Specialized cases only | No protection, vulnerable to multiple attack vectors | |
| 81 | + |
| 82 | +#### Detailed padding explanations |
| 83 | + |
| 84 | +<details> |
| 85 | + <summary> `pkcs1` padding: The nostalgic option</summary> |
| 86 | + |
| 87 | + Think of `pkcs1` padding as the security equivalent of a 90s-era car alarm. It adds random stuffing to your message to stop pattern analysis, making your message look different each time. It's decent protection against casual thieves but not against determined professionals with modern tools. It's like putting your valuables in a safe that shouts "HEY! I'M A SAFE!" when touched. |
| 88 | +</details> |
| 89 | + |
| 90 | +<details> |
| 91 | + <summary> `oaep` padding: The recommended secure option</summary> |
| 92 | + |
| 93 | + `oaep` padding (Optimal Asymmetric Encryption Padding) implements a mathematically robust random mask that significantly increases resistance to cryptanalysis (the science of breaking encryption). This method applies multiple layers of protection to the encrypted data, making it the recommended option for systems requiring high security standards. The additional computational overhead is justified by the enhanced security protections it provides. |
| 94 | +</details> |
| 95 | + |
| 96 | +<details> |
| 97 | + <summary> `no` padding: Non-secure implementation option</summary> |
| 98 | + |
| 99 | + The unpadded encryption implementation provides no additional cryptographic protection for the message content. This approach eliminates randomization elements, exposing the encrypted data to various cryptanalytic attacks including pattern analysis. This option should only be implemented in specialized circumstances where compatibility with specific systems is required or where separate security controls are implemented at another layer. Not recommended for standard security implementations. |
| 100 | +</details> |
| 101 | + |
| 102 | + |
| 103 | +### Signature padding options |
| 104 | + |
| 105 | +| Padding Type | Security Level | Characteristics | Best For | |
| 106 | +|-------------|---------------|-----------------|----------| |
| 107 | +| `pkcs1` | Standard | Consistent signatures | Compatibility with older systems | |
| 108 | +| `pkcs1_pss` | High | Unique signature every time | Modern security needs | |
| 109 | + |
| 110 | +<details> |
| 111 | + <summary> `pkcs1` padding: The basic signature</summary> |
| 112 | + |
| 113 | + `pkcs1` padding for signatures is like signing your name the same way every time. It takes your message, creates a fingerprint, adds some standard framing, and locks it with your private key. It works fine until someone figures out how to copy your signature style, at which point your security is compromised. It's simple and compatible with older systems, but not the strongest option available. |
| 114 | +</details> |
| 115 | + |
| 116 | +<details> |
| 117 | + <summary> `pkcs1_pss` padding: The signature with flair</summary> |
| 118 | + |
| 119 | + `pkcs1_pss` padding is like adding a unique flourish to your signature every single time. Even when signing the exact same document twice, the signatures will look completely different - yet both will verify correctly. This makes signature forgery dramatically harder, as there's no consistent pattern to copy. If you're serious about security (and if you're reading this, you should be), this is your go-to option. |
| 120 | +</details> |
| 121 | + |
| 122 | + |
| 123 | +### Other new features |
| 124 | + |
| 125 | +* [`encryption_udf.legacy_padding_scheme`](#encryption_udflegacy_padding_scheme) system variable - provides compatibility with legacy systems and previous implementations |
| 126 | + |
| 127 | +* Character set awareness - ensures proper handling of different character encodings during encryption operations |
| 128 | + |
| 129 | +Percona Server for MySQL 8.0.28-20 introduces tools for selective data encryption, allowing precise control over which data elements receive encryption protections. |
| 130 | + |
| 131 | +## Character sets and component encryption UDFs |
| 132 | + |
| 133 | +> 🏭 **Automated feature** |
| 134 | +> |
| 135 | +> These functions automatically manage character sets, eliminating the need for manual character encoding management during encryption operations. |
| 136 | +
|
| 137 | +The implementation handles complex character set conversions internally, allowing developers to focus on encryption logic rather than encoding issues. |
| 138 | + |
| 139 | +### What happens to your input |
| 140 | + |
| 141 | +| Input Type | What Happens | Why It Matters | |
| 142 | +|------------|--------------|----------------| |
| 143 | +| Algorithms, digest names, keys | Automatically converted to ASCII | Prevents character encoding mismatches between encryption and decryption operations | |
| 144 | +| Messages and signatures | Transformed into raw binary | Computers process binary, not human-readable formats | |
| 145 | + |
| 146 | + |
| 147 | +### What you get back |
| 148 | + |
| 149 | +| Output Type | Format | What to Expect | |
| 150 | +|------------|--------|----------------| |
| 151 | +| Key files | Human-readable ASCII text | Viewable without terminal issues | |
| 152 | +| Encrypted messages & signatures | Binary data | Looks like gibberish (this is correct!) | |
| 153 | + |
| 154 | +## External key management |
| 155 | + |
| 156 | +> 🔒 **External Key Management** |
| 157 | +> |
| 158 | +> For enhanced security, cryptographic keys can be generated outside the database server using dedicated cryptographic tools and hardware. |
| 159 | +
|
| 160 | +Keys can be generated externally with OpenSSL and imported into the system. This approach separates key generation from the database environment, reducing the attack surface and allowing for specialized key generation hardware if required. |
| 161 | + |
| 162 | + |
| 163 | +### External key generation |
| 164 | + |
| 165 | +| Tool | Command Example | What It Creates | |
| 166 | +|------|----------------|-----------------| |
| 167 | +| OpenSSL | `openssl genrsa -out private.pem 2048` | RSA private key | |
| 168 | +| OpenSSL | `openssl rsa -in private.pem -pubout -out public.pem` | RSA public key from private key | |
| 169 | +| OpenSSL | `openssl dsaparam -genkey 2048 -out dsaprivate.pem` | DSA private key | |
| 170 | + |
| 171 | +Your OpenSSL-generated keys work seamlessly with these functions - just read the PEM file and pass its content to the encryption functions. |
| 172 | + |
| 173 | + |
| 174 | +### How you might break this |
| 175 | + |
| 176 | +⚠️ **Common Mistakes With External Keys:** |
| 177 | + |
| 178 | +* Importing a key in the wrong format |
| 179 | + |
| 180 | +* Using a key type incompatible with your chosen algorithm |
| 181 | + |
| 182 | +* Forgetting to remove newlines from PEM files when storing in variables |
| 183 | + |
| 184 | +* Storing keys directly in your database without proper protection |
| 185 | + |
| 186 | +If you encounter any of these issues, you may receive a non-descriptive error message. Ensure that your keys are correctly formatted and stored securely. |
| 187 | + |
| 188 | + |
0 commit comments