|
| 1 | +require 'openssl' |
| 2 | + |
| 3 | +# BAD: creating a cipher using a weak scheme |
| 4 | +weak = OpenSSL::Cipher.new('des3') |
| 5 | +weak.encrypt |
| 6 | +weak.random_key |
| 7 | +# BAD: encrypting data using a weak cipher |
| 8 | +weak.update('foo') |
| 9 | +weak.final |
| 10 | + |
| 11 | +# BAD: creating a cipher using a weak block mode |
| 12 | +weak = OpenSSL::Cipher::AES.new(128, 'ecb') |
| 13 | +weak.encrypt |
| 14 | +weak.random_key |
| 15 | +# BAD: encrypting data using a weak block mode |
| 16 | +weak.update('foo') |
| 17 | +weak.final |
| 18 | + |
| 19 | +# GOOD: creating a cipher using a strong scheme |
| 20 | +strong = OpenSSL::Cipher.new('blowfish') |
| 21 | +strong.encrypt |
| 22 | +strong.random_key |
| 23 | +# GOOD: encrypting data using a strong cipher |
| 24 | +strong.update('bar') |
| 25 | +strong.final |
| 26 | + |
| 27 | +# BAD: weak block mode |
| 28 | +OpenSSL::Cipher::AES.new(128, :ecb) |
| 29 | +# GOOD: strong encryption algorithm |
| 30 | +OpenSSL::Cipher::AES.new(128, 'cbc') |
| 31 | +# GOOD: strong encryption algorithm |
| 32 | +OpenSSL::Cipher::AES.new('128-cbc') |
| 33 | + |
| 34 | +# GOOD: strong encryption algorithm |
| 35 | +OpenSSL::Cipher::AES128.new |
| 36 | +# BAD: weak block mode |
| 37 | +OpenSSL::Cipher::AES128.new 'ecb' |
| 38 | + |
| 39 | +# GOOD: strong encryption algorithm |
| 40 | +OpenSSL::Cipher::AES192.new |
| 41 | +# BAD: weak block mode |
| 42 | +OpenSSL::Cipher::AES192.new 'ecb' |
| 43 | + |
| 44 | +# GOOD: strong encryption algorithm |
| 45 | +OpenSSL::Cipher::AES256.new |
| 46 | +# BAD: weak block mode |
| 47 | +OpenSSL::Cipher::AES256.new 'ecb' |
| 48 | + |
| 49 | +# GOOD: strong encryption algorithm |
| 50 | +OpenSSL::Cipher::BF.new |
| 51 | +# BAD: weak block mode |
| 52 | +OpenSSL::Cipher::BF.new 'ecb' |
| 53 | + |
| 54 | +# GOOD: strong encryption algorithm |
| 55 | +OpenSSL::Cipher::CAST5.new |
| 56 | +# BAD: weak block mode |
| 57 | +OpenSSL::Cipher::CAST5.new 'ecb' |
| 58 | + |
| 59 | +# BAD: weak encryption algorithm |
| 60 | +OpenSSL::Cipher::DES.new |
| 61 | +# BAD: weak encryption algorithm |
| 62 | +OpenSSL::Cipher::DES.new 'cbc' |
| 63 | + |
| 64 | +# GOOD: strong encryption algorithm |
| 65 | +OpenSSL::Cipher::IDEA.new |
| 66 | +# BAD: weak block mode |
| 67 | +OpenSSL::Cipher::IDEA.new 'ecb' |
| 68 | + |
| 69 | +# BAD: weak encryption algorithm |
| 70 | +OpenSSL::Cipher::RC2.new |
| 71 | +# BAD: weak encryption algorithm |
| 72 | +OpenSSL::Cipher::RC2.new 'ecb' |
| 73 | + |
| 74 | +# BAD: weak encryption algorithm |
| 75 | +OpenSSL::Cipher::RC4.new |
| 76 | +# BAD: weak encryption algorithm |
| 77 | +OpenSSL::Cipher::RC4.new '40' |
| 78 | +# BAD: weak encryption algorithm |
| 79 | +OpenSSL::Cipher::RC4.new 'hmac-md5' |
0 commit comments