sandal 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +14 -0
- data/README.md +1 -1
- data/lib/sandal.rb +77 -76
- data/lib/sandal/claims.rb +13 -13
- data/lib/sandal/enc.rb +15 -49
- data/lib/sandal/enc/acbc_hs.rb +97 -52
- data/lib/sandal/enc/agcm.rb +64 -26
- data/lib/sandal/enc/alg.rb +2 -3
- data/lib/sandal/enc/alg/direct.rb +27 -25
- data/lib/sandal/enc/alg/rsa.rb +82 -0
- data/lib/sandal/sig.rb +12 -12
- data/lib/sandal/sig/es.rb +43 -25
- data/lib/sandal/sig/hs.rb +21 -8
- data/lib/sandal/sig/rs.rb +34 -23
- data/lib/sandal/util.rb +7 -7
- data/lib/sandal/version.rb +1 -1
- data/spec/helper.rb +1 -0
- data/spec/sample_keys.rb +28 -0
- data/spec/sandal/claims_spec.rb +4 -4
- data/spec/sandal/enc/a128cbc_hs256_spec.rb +15 -39
- data/spec/sandal/enc/a128gcm_spec.rb +13 -6
- data/spec/sandal/enc/a256cbc_hs512_spec.rb +13 -4
- data/spec/sandal/enc/a256gcm_spec.rb +15 -37
- data/spec/sandal/enc/alg/direct_spec.rb +27 -33
- data/spec/sandal/enc/alg/rsa_spec.rb +100 -0
- data/spec/sandal/enc/shared_examples.rb +93 -21
- data/spec/sandal/sig/es_spec.rb +145 -188
- data/spec/sandal/sig/hs_spec.rb +73 -18
- data/spec/sandal/sig/rs_spec.rb +81 -78
- metadata +7 -6
- data/lib/sandal/enc/alg/rsa1_5.rb +0 -47
- data/lib/sandal/enc/alg/rsa_oaep.rb +0 -48
- data/spec/sandal/enc/alg/rsa1_5_spec.rb +0 -40
data/spec/sandal/sig/rs_spec.rb
CHANGED
@@ -1,106 +1,109 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
rsa_private_key = <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UF0gPlK0REa2wiEvpd00
|
38
|
-
D46Sfxfa5kpe/oYajCyRtesmGyrDiD4BKJIaHTal4613l1k8HWhzza4qztbufZ4B
|
39
|
-
MPfHkjyjOBWLsYSU0axI86b5WnxJKZUyghxeL51jYqV5eSeMBC3rr+HHuwdF3ulh
|
40
|
-
vDo0jUxGjFJBG/6ZUheVNAGrAvD85RV3tp8ukcc02t2l0Z97PWDcZHpiiul+Dvvm
|
41
|
-
eQIDAQAB
|
42
|
-
-----END PUBLIC KEY-----
|
43
|
-
KEY_END
|
1
|
+
require "helper"
|
2
|
+
require "openssl"
|
44
3
|
|
45
|
-
|
4
|
+
shared_examples "signing and validation" do |enc_class|
|
46
5
|
|
47
|
-
it
|
48
|
-
data =
|
6
|
+
it "can sign data and validate signatures" do
|
7
|
+
data = "this is my data"
|
49
8
|
private_key = OpenSSL::PKey::RSA.generate(2048)
|
50
|
-
signer =
|
9
|
+
signer = enc_class.new(private_key)
|
51
10
|
signature = signer.sign(data)
|
52
|
-
validator =
|
11
|
+
validator = enc_class.new(private_key.public_key)
|
53
12
|
validator.valid?(signature, data).should == true
|
54
13
|
end
|
55
14
|
|
56
|
-
it
|
57
|
-
data =
|
58
|
-
|
15
|
+
it "can use DER-encoded keys to sign data and validate signatures" do
|
16
|
+
data = "there are many like it"
|
17
|
+
private_key = OpenSSL::PKey::RSA.generate(2048)
|
18
|
+
signer = enc_class.new(private_key.to_der)
|
59
19
|
signature = signer.sign(data)
|
60
|
-
validator =
|
20
|
+
validator = enc_class.new(private_key.public_key.to_der)
|
61
21
|
validator.valid?(signature, data).should == true
|
62
22
|
end
|
63
23
|
|
24
|
+
it "can use PEM-encoded keys to sign data and validate signatures" do
|
25
|
+
data = "but this one is mine"
|
26
|
+
private_key = OpenSSL::PKey::RSA.generate(2048)
|
27
|
+
signer = enc_class.new(private_key.to_pem)
|
28
|
+
signature = signer.sign(data)
|
29
|
+
validator = enc_class.new(private_key.public_key.to_pem)
|
30
|
+
validator.valid?(signature, data).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#valid?" do
|
34
|
+
|
35
|
+
it "fails to validate the signature when the key is changed" do
|
36
|
+
data = "this is my data"
|
37
|
+
signer = enc_class.new(OpenSSL::PKey::RSA.generate(2048))
|
38
|
+
signature = signer.sign(data)
|
39
|
+
validator = enc_class.new(OpenSSL::PKey::RSA.generate(2048).public_key)
|
40
|
+
validator.valid?(signature, data).should == false
|
41
|
+
end
|
42
|
+
|
43
|
+
it "fails to validate the signature when the signature is changed" do
|
44
|
+
data = "this is my data"
|
45
|
+
private_key = OpenSSL::PKey::RSA.generate(2048)
|
46
|
+
signer = enc_class.new(private_key)
|
47
|
+
signature = signer.sign(data)
|
48
|
+
validator = enc_class.new(private_key.public_key)
|
49
|
+
validator.valid?(signature + "x", data).should == false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "fails to validate the signature when the data is changed" do
|
53
|
+
data = "this is my data"
|
54
|
+
private_key = OpenSSL::PKey::RSA.generate(2048)
|
55
|
+
signer = enc_class.new(private_key)
|
56
|
+
signature = signer.sign(data)
|
57
|
+
validator = enc_class.new(private_key.public_key)
|
58
|
+
validator.valid?(signature, data + "x").should == false
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
64
63
|
end
|
65
64
|
|
66
|
-
describe Sandal::Sig::RS384 do
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
describe Sandal::Sig::RS256 do
|
67
|
+
include_examples "signing and validation", Sandal::Sig::RS256
|
68
|
+
|
69
|
+
it "can validate the signature from JWS dratf-11 appendix 2", :jruby_incompatible do
|
70
|
+
data = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ"
|
71
|
+
private_key = SampleKeys.jws_draft11_appendix2_rsa
|
71
72
|
signer = Sandal::Sig::RS384.new(private_key)
|
72
73
|
signature = signer.sign(data)
|
73
74
|
validator = Sandal::Sig::RS384.new(private_key.public_key)
|
74
75
|
validator.valid?(signature, data).should == true
|
76
|
+
end
|
77
|
+
|
78
|
+
context "#name" do
|
79
|
+
it "is 'RS256'" do
|
80
|
+
enc = Sandal::Sig::RS256.new(OpenSSL::PKey::RSA.generate(2048))
|
81
|
+
enc.name.should == "RS256"
|
82
|
+
end
|
75
83
|
end
|
76
84
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Sandal::Sig::RS384 do
|
88
|
+
include_examples "signing and validation", Sandal::Sig::RS384
|
89
|
+
|
90
|
+
context "#name" do
|
91
|
+
it "is 'RS384'" do
|
92
|
+
enc = Sandal::Sig::RS384.new(OpenSSL::PKey::RSA.generate(2048))
|
93
|
+
enc.name.should == "RS384"
|
94
|
+
end
|
83
95
|
end
|
84
96
|
|
85
97
|
end
|
86
98
|
|
87
99
|
describe Sandal::Sig::RS512 do
|
88
|
-
|
89
|
-
it 'can sign data and verify signatures' do
|
90
|
-
data = 'Hello RS512'
|
91
|
-
private_key = OpenSSL::PKey::RSA.generate(2048)
|
92
|
-
signer = Sandal::Sig::RS512.new(private_key)
|
93
|
-
signature = signer.sign(data)
|
94
|
-
validator = Sandal::Sig::RS512.new(private_key.public_key)
|
95
|
-
validator.valid?(signature, data).should == true
|
96
|
-
end
|
100
|
+
include_examples "signing and validation", Sandal::Sig::RS512
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
validator.valid?(signature, data).should == true
|
102
|
+
context "#name" do
|
103
|
+
it "is 'RS512'" do
|
104
|
+
enc = Sandal::Sig::RS512.new(OpenSSL::PKey::RSA.generate(2048))
|
105
|
+
enc.name.should == "RS512"
|
106
|
+
end
|
104
107
|
end
|
105
|
-
|
108
|
+
|
106
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Beech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -148,8 +148,7 @@ files:
|
|
148
148
|
- lib/sandal/enc/agcm.rb
|
149
149
|
- lib/sandal/enc/alg.rb
|
150
150
|
- lib/sandal/enc/alg/direct.rb
|
151
|
-
- lib/sandal/enc/alg/
|
152
|
-
- lib/sandal/enc/alg/rsa_oaep.rb
|
151
|
+
- lib/sandal/enc/alg/rsa.rb
|
153
152
|
- lib/sandal/sig.rb
|
154
153
|
- lib/sandal/sig/es.rb
|
155
154
|
- lib/sandal/sig/hs.rb
|
@@ -158,13 +157,14 @@ files:
|
|
158
157
|
- lib/sandal/version.rb
|
159
158
|
- sandal.gemspec
|
160
159
|
- spec/helper.rb
|
160
|
+
- spec/sample_keys.rb
|
161
161
|
- spec/sandal/claims_spec.rb
|
162
162
|
- spec/sandal/enc/a128cbc_hs256_spec.rb
|
163
163
|
- spec/sandal/enc/a128gcm_spec.rb
|
164
164
|
- spec/sandal/enc/a256cbc_hs512_spec.rb
|
165
165
|
- spec/sandal/enc/a256gcm_spec.rb
|
166
166
|
- spec/sandal/enc/alg/direct_spec.rb
|
167
|
-
- spec/sandal/enc/alg/
|
167
|
+
- spec/sandal/enc/alg/rsa_spec.rb
|
168
168
|
- spec/sandal/enc/shared_examples.rb
|
169
169
|
- spec/sandal/sig/es_spec.rb
|
170
170
|
- spec/sandal/sig/hs_spec.rb
|
@@ -198,13 +198,14 @@ specification_version: 4
|
|
198
198
|
summary: A JSON Web Token (JWT) library.
|
199
199
|
test_files:
|
200
200
|
- spec/helper.rb
|
201
|
+
- spec/sample_keys.rb
|
201
202
|
- spec/sandal/claims_spec.rb
|
202
203
|
- spec/sandal/enc/a128cbc_hs256_spec.rb
|
203
204
|
- spec/sandal/enc/a128gcm_spec.rb
|
204
205
|
- spec/sandal/enc/a256cbc_hs512_spec.rb
|
205
206
|
- spec/sandal/enc/a256gcm_spec.rb
|
206
207
|
- spec/sandal/enc/alg/direct_spec.rb
|
207
|
-
- spec/sandal/enc/alg/
|
208
|
+
- spec/sandal/enc/alg/rsa_spec.rb
|
208
209
|
- spec/sandal/enc/shared_examples.rb
|
209
210
|
- spec/sandal/sig/es_spec.rb
|
210
211
|
- spec/sandal/sig/hs_spec.rb
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
|
3
|
-
module Sandal
|
4
|
-
module Enc
|
5
|
-
module Alg
|
6
|
-
|
7
|
-
# The RSAES-PKCS1-V1_5 key encryption mechanism.
|
8
|
-
class RSA1_5
|
9
|
-
|
10
|
-
# @return [String] The JWA name of the algorithm.
|
11
|
-
attr_reader :name
|
12
|
-
|
13
|
-
# Creates a new instance.
|
14
|
-
#
|
15
|
-
# @param key [OpenSSL::PKey::RSA or String] The key to use for CMK
|
16
|
-
# encryption (public) or decryption (private). If the value is a String
|
17
|
-
# then it will be passed to the constructor of the RSA class. This must
|
18
|
-
# be at least 2048 bits to be compliant with the JWA specification.
|
19
|
-
def initialize(key)
|
20
|
-
@name = 'RSA1_5'
|
21
|
-
@key = key.is_a?(String) ? OpenSSL::PKey::RSA.new(key) : key
|
22
|
-
end
|
23
|
-
|
24
|
-
# Encrypts the content master key.
|
25
|
-
#
|
26
|
-
# @param cmk [String] The content master key.
|
27
|
-
# @return [String] The encrypted content master key.
|
28
|
-
def encrypt_cmk(cmk)
|
29
|
-
@key.public_encrypt(cmk)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Decrypts the content master key.
|
33
|
-
#
|
34
|
-
# @param encrypted_cmk [String] The encrypted content master key.
|
35
|
-
# @return [String] The pre-shared content master key.
|
36
|
-
# @raise [Sandal::TokenError] The content master key can't be decrypted.
|
37
|
-
def decrypt_cmk(encrypted_cmk)
|
38
|
-
@key.private_decrypt(encrypted_cmk)
|
39
|
-
rescue
|
40
|
-
raise Sandal::TokenError, 'Cannot decrypt content master key.'
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
|
3
|
-
module Sandal
|
4
|
-
module Enc
|
5
|
-
module Alg
|
6
|
-
|
7
|
-
# The RSAES with OAEP key encryption mechanism.
|
8
|
-
class RSA_OAEP
|
9
|
-
|
10
|
-
# @return [String] The JWA name of the algorithm.
|
11
|
-
attr_reader :name
|
12
|
-
|
13
|
-
# Creates a new instance.
|
14
|
-
#
|
15
|
-
# @param key [OpenSSL::PKey::RSA or String] The key to use for CMK
|
16
|
-
# encryption (public) or decryption (private). If the value is a String
|
17
|
-
# then it will be passed to the constructor of the RSA class. This must
|
18
|
-
# be at least 2048 bits to be compliant with the JWA specification.
|
19
|
-
def initialize(key)
|
20
|
-
@name = 'RSA-OAEP'
|
21
|
-
@key = key.is_a?(String) ? OpenSSL::PKey::RSA.new(key) : key
|
22
|
-
@padding = OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING
|
23
|
-
end
|
24
|
-
|
25
|
-
# Encrypts the content master key.
|
26
|
-
#
|
27
|
-
# @param cmk [String] The content master key.
|
28
|
-
# @return [String] The encrypted content master key.
|
29
|
-
def encrypt_cmk(cmk)
|
30
|
-
@key.public_encrypt(cmk, @padding)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Decrypts the content master key.
|
34
|
-
#
|
35
|
-
# @param encrypted_cmk [String] The encrypted content master key.
|
36
|
-
# @return [String] The pre-shared content master key.
|
37
|
-
# @raise [Sandal::TokenError] The content master key can't be decrypted.
|
38
|
-
def decrypt_cmk(encrypted_cmk)
|
39
|
-
@key.private_decrypt(encrypted_cmk, @padding)
|
40
|
-
rescue
|
41
|
-
raise Sandal::TokenError, 'Cannot decrypt content master key.'
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'openssl'
|
3
|
-
|
4
|
-
include Sandal::Util
|
5
|
-
|
6
|
-
describe Sandal::Enc::Alg::RSA1_5 do
|
7
|
-
|
8
|
-
context '#name' do
|
9
|
-
|
10
|
-
it 'is "RSA1_5"' do
|
11
|
-
alg = Sandal::Enc::Alg::RSA1_5.new(OpenSSL::PKey::RSA.new(2048))
|
12
|
-
alg.name.should == 'RSA1_5'
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context '#decrypt_cmk' do
|
18
|
-
|
19
|
-
it 'can decrypt the encypted content master key from JWE section A.2', :jruby_incompatible do
|
20
|
-
key = OpenSSL::PKey::RSA.new(2048)
|
21
|
-
key.n = make_bn([177, 119, 33, 13, 164, 30, 108, 121, 207, 136, 107, 242, 12, 224, 19, 226, 198, 134, 17, 71, 173, 75, 42, 61, 48, 162, 206, 161, 97, 108, 185, 234, 226, 219, 118, 206, 118, 5, 169, 224, 60, 181, 90, 85, 51, 123, 6, 224, 4, 122, 29, 230, 151, 12, 244, 127, 121, 25, 4, 85, 220, 144, 215, 110, 130, 17, 68, 228, 129, 138, 7, 130, 231, 40, 212, 214, 17, 179, 28, 124, 151, 178, 207, 20, 14, 154, 222, 113, 176, 24, 198, 73, 211, 113, 9, 33, 178, 80, 13, 25, 21, 25, 153, 212, 206, 67, 154, 147, 70, 194, 192, 183, 160, 83, 98, 236, 175, 85, 23, 97, 75, 199, 177, 73, 145, 50, 253, 206, 32, 179, 254, 236, 190, 82, 73, 67, 129, 253, 252, 220, 108, 136, 138, 11, 192, 1, 36, 239, 228, 55, 81, 113, 17, 25, 140, 63, 239, 146, 3, 172, 96, 60, 227, 233, 64, 255, 224, 173, 225, 228, 229, 92, 112, 72, 99, 97, 26, 87, 187, 123, 46, 50, 90, 202, 117, 73, 10, 153, 47, 224, 178, 163, 77, 48, 46, 154, 33, 148, 34, 228, 33, 172, 216, 89, 46, 225, 127, 68, 146, 234, 30, 147, 54, 146, 5, 133, 45, 78, 254, 85, 55, 75, 213, 86, 194, 218, 215, 163, 189, 194, 54, 6, 83, 36, 18, 153, 53, 7, 48, 89, 35, 66, 144, 7, 65, 154, 13, 97, 75, 55, 230, 132, 3, 13, 239, 71])
|
22
|
-
key.e = make_bn([1, 0, 1])
|
23
|
-
key.d = make_bn([84, 80, 150, 58, 165, 235, 242, 123, 217, 55, 38, 154, 36, 181, 221, 156, 211, 215, 100, 164, 90, 88, 40, 228, 83, 148, 54, 122, 4, 16, 165, 48, 76, 194, 26, 107, 51, 53, 179, 165, 31, 18, 198, 173, 78, 61, 56, 97, 252, 158, 140, 80, 63, 25, 223, 156, 36, 203, 214, 252, 120, 67, 180, 167, 3, 82, 243, 25, 97, 214, 83, 133, 69, 16, 104, 54, 160, 200, 41, 83, 164, 187, 70, 153, 111, 234, 242, 158, 175, 28, 198, 48, 211, 45, 148, 58, 23, 62, 227, 74, 52, 117, 42, 90, 41, 249, 130, 154, 80, 119, 61, 26, 193, 40, 125, 10, 152, 174, 227, 225, 205, 32, 62, 66, 6, 163, 100, 99, 219, 19, 253, 25, 105, 80, 201, 29, 252, 157, 237, 69, 1, 80, 171, 167, 20, 196, 156, 109, 249, 88, 0, 3, 152, 38, 165, 72, 87, 6, 152, 71, 156, 214, 16, 71, 30, 82, 51, 103, 76, 218, 63, 9, 84, 163, 249, 91, 215, 44, 238, 85, 101, 240, 148, 1, 82, 224, 91, 135, 105, 127, 84, 171, 181, 152, 210, 183, 126, 24, 46, 196, 90, 173, 38, 245, 219, 186, 222, 27, 240, 212, 194, 15, 66, 135, 226, 178, 190, 52, 245, 74, 65, 224, 81, 100, 85, 25, 204, 165, 203, 187, 175, 84, 100, 82, 15, 11, 23, 202, 151, 107, 54, 41, 207, 3, 136, 229, 134, 131, 93, 139, 50, 182, 204, 93, 130, 89])
|
24
|
-
cmk = [4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207].pack('C*')
|
25
|
-
encrypted_cmk = jwt_base64_decode('ZmnlqWgjXyqwjr7cXHys8F79anIUI6J2UWdAyRQEcGBU-KPHsePM910_RoTDGu1IW40Dn0dvcdVEjpJcPPNIbzWcMxDi131Ejeg-b8ViW5YX5oRdYdiR4gMSDDB3mbkInMNUFT-PK5CuZRnHB2rUK5fhPuF6XFqLLZCG5Q_rJm6Evex-XLcNQAJNa1-6CIU12Wj3mPExxw9vbnsQDU7B4BfmhdyiflLA7Ae5ZGoVRl3A__yLPXxRjHFhpOeDp_adx8NyejF5cz9yDKULugNsDMdlHeJQOMGVLYaSZt3KP6aWNSqFA1PHDg-10ceuTEtq_vPE4-Gtev4N4K4Eudlj4Q')
|
26
|
-
alg = Sandal::Enc::Alg::RSA1_5.new(key)
|
27
|
-
alg.decrypt_cmk(encrypted_cmk).should == cmk
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises a TokenError when the wrong key is used for decryption' do
|
31
|
-
key = OpenSSL::PKey::RSA.new(2048)
|
32
|
-
cmk = [4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207].pack('C*')
|
33
|
-
encrypted_cmk = jwt_base64_decode('ZmnlqWgjXyqwjr7cXHys8F79anIUI6J2UWdAyRQEcGBU-KPHsePM910_RoTDGu1IW40Dn0dvcdVEjpJcPPNIbzWcMxDi131Ejeg-b8ViW5YX5oRdYdiR4gMSDDB3mbkInMNUFT-PK5CuZRnHB2rUK5fhPuF6XFqLLZCG5Q_rJm6Evex-XLcNQAJNa1-6CIU12Wj3mPExxw9vbnsQDU7B4BfmhdyiflLA7Ae5ZGoVRl3A__yLPXxRjHFhpOeDp_adx8NyejF5cz9yDKULugNsDMdlHeJQOMGVLYaSZt3KP6aWNSqFA1PHDg-10ceuTEtq_vPE4-Gtev4N4K4Eudlj4Q')
|
34
|
-
alg = Sandal::Enc::Alg::RSA1_5.new(key)
|
35
|
-
expect { alg.decrypt_cmk(encrypted_cmk) }.to raise_error Sandal::TokenError, 'Cannot decrypt content master key.'
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|