Encryption in Ruby
Encode and decode
Use Base64. API
- Unreadable.
- Translates any binary data into purely printable characters. Eg. in HTTP transmission(MIME).
- Use
a-zA-Z0-9+/
. When encode URL, usea-zA-Z0-9_-
1 2 3 4 5 6 7 8 9 10 |
|
Secure Random String
Use SecureRandom, an interface for secure random number generator. API
- Generate session key in HTTP cookies.
- Generate OAuth nonce.
1
|
|
Hex presentation.
1 2 3 4 5 6 7 8 |
|
Base64 presentation.
1 2 |
|
Digest
Use SHA(Secure Hash Algorithm) to generate digest and encrypt. API
1
|
|
Binary presentation.
1 2 |
|
Hex presentation.
1 2 |
|
Base64 presentation.
1 2 |
|
Bubble-babble (recognizable and pronounceable) presentation
1 2 3 4 |
|
Use SHA2.
1 2 |
|
Use MD5.(abandoned)
1 2 |
|
HMAC
Use OpenSSL::HMAC. API
Hash-based Message Authentication Code.
- Generate digest message.
- Sign it.
1 2 3 4 5 6 7 8 9 10 11 |
|
Symmetric Encryption and Decryption
Use OpenSSL::Cipher. API
List all supported algorithms.
1 2 3 4 5 6 7 8 |
|
Encrytion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Decryption.
1 2 3 4 5 6 7 8 9 10 11 12 |
|