-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryption_decryption.rb
More file actions
53 lines (48 loc) · 1.54 KB
/
encryption_decryption.rb
File metadata and controls
53 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# require 'encryption'
# def encrypt(input)
# encryptor = Encryption::Symmetric.new
# # 256-bit encryption key - AES (Symmetric)
# encryptor.key = '7w!z%C*F)J@NcRfUjXn2r5u8x/A?D(G+'
# encryptor.iv = 'Xn2r5u8x/A?D(G+K'
# encrypted_str = nil
# if input.is_a?(Array)
# encrypted_list = input.map{|item| encryptor.encrypt(item)}
# return encrypted_list
# else
# encrypted_str = encryptor.encrypt(input)
# return encrypted_str
# end
# end
# def decrypt(input)
# encryptor = Encryption::Symmetric.new
# # 256-bit encryption key - AES (Symmetric)
# encryptor.key = '7w!z%C*F)J@NcRfUjXn2r5u8x/A?D(G+'
# encryptor.iv = 'Xn2r5u8x/A?D(G+K'
# encrypted_str = nil
# if input.is_a?(Array)
# decrypted_list = input.map{|item| encryptor.decrypt(item)}
# return decrypted_list
# else
# decrypted_str = encryptor.decrypt(input)
# return decrypted_str
# end
# end
require 'symmetric-encryption'
def encrypt(input)
SymmetricEncryption.cipher = SymmetricEncryption::Cipher.new(
key: '7w!z%C*F)J@NcRfU',
iv: 'Xn2r5u8x/A?D(G+K',
cipher_name: 'aes-128-cbc'
)
encrypted_str = nil
if input.is_a?(Array)
encrypted_list = input.map{|item| SymmetricEncryption.encrypt(item)}
return encrypted_list
else
encrypted_str = encrypted = SymmetricEncryption.encrypt(input)
return encrypted_str
end
end
text = 'This is a sample piece of text'
encrypted = encrypt(text)
puts encrypted