Class: WSS4R::Security::Crypto::SymmetricEncrypter
- Inherits:
-
Object
- Object
- WSS4R::Security::Crypto::SymmetricEncrypter
show all
- Defined in:
- lib/wss4r/security/crypto/cipher.rb
Instance Method Summary
collapse
Constructor Details
#initialize(algorithm, key = nil, iv = nil) ⇒ SymmetricEncrypter
Returns a new instance of SymmetricEncrypter.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 6
def initialize(algorithm, key = nil, iv = nil)
@cipher = Cipher.new(algorithm)
@algorithm = algorithm
if (iv == nil)
@iv = @cipher.random_iv()
else
@iv = iv
end
if (key == nil)
@key = @cipher.random_key()
else
@key = key
end
end
|
Instance Method Details
#decrypt(text) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 29
def decrypt(text)
@cipher.decrypt(@key, @iv)
@cipher.key = @key
@cipher.iv = @iv
cipher = @cipher.update(text[8..-1])
cipher << @cipher.final()
cipher
end
|
#encrypt_to_b64(text) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 21
def encrypt_to_b64(text)
@cipher.encrypt(@key, @iv)
@cipher.key = @key
cipher = @cipher.update(text)
cipher << @cipher.final()
Base64.encode64(cipher)
end
|
#iv ⇒ Object
38
39
40
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 38
def iv()
@iv
end
|
#iv_b64 ⇒ Object
50
51
52
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 50
def iv_b64()
Base64.encode64(@iv)
end
|
#key ⇒ Object
42
43
44
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 42
def key()
@key
end
|
#key=(key) ⇒ Object
46
47
48
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 46
def key=(key)
@key
end
|
#key_b64 ⇒ Object
54
55
56
|
# File 'lib/wss4r/security/crypto/cipher.rb', line 54
def key_b64()
Base64.encode64(@key)
end
|