-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathimpl_js.rsaoaep.dart
More file actions
212 lines (186 loc) · 5.41 KB
/
impl_js.rsaoaep.dart
File metadata and controls
212 lines (186 loc) · 5.41 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ignore_for_file: non_constant_identifier_names
part of 'impl_js.dart';
const _rsaOaepAlgorithmName = 'RSA-OAEP';
Future<RsaOaepPrivateKeyImpl> rsaOaepPrivateKey_importPkcs8Key(
List<int> keyData,
HashImpl hash,
) async {
return _RsaOaepPrivateKeyImpl(await _importKey(
'pkcs8',
keyData,
subtle.Algorithm(
name: _rsaOaepAlgorithmName,
hash: _getHashAlgorithm(hash),
),
_usagesDecrypt,
'private',
));
}
Future<RsaOaepPrivateKeyImpl> rsaOaepPrivateKey_importJsonWebKey(
Map<String, dynamic> jwk,
HashImpl hash,
) async {
return _RsaOaepPrivateKeyImpl(await _importJsonWebKey(
jwk,
subtle.Algorithm(
name: _rsaOaepAlgorithmName,
hash: _getHashAlgorithm(hash),
),
_usagesDecrypt,
'private',
));
}
Future<KeyPair<RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl>>
rsaOaepPrivateKey_generateKey(
int modulusLength,
BigInt publicExponent,
HashImpl hash,
) async {
final pair = await _generateKeyPair(
subtle.Algorithm(
name: _rsaOaepAlgorithmName,
hash: _getHashAlgorithm(hash),
publicExponent: _publicExponentAsBuffer(publicExponent),
modulusLength: modulusLength,
),
_usagesEncryptDecrypt,
);
return (
privateKey: _RsaOaepPrivateKeyImpl(pair.privateKey),
publicKey: _RsaOaepPublicKeyImpl(pair.publicKey),
);
}
Future<RsaOaepPublicKeyImpl> rsaOaepPublicKey_importSpkiKey(
List<int> keyData,
HashImpl hash,
) async {
return _RsaOaepPublicKeyImpl(await _importKey(
'spki',
keyData,
subtle.Algorithm(
name: _rsaOaepAlgorithmName,
hash: _getHashAlgorithm(hash),
),
_usagesEncrypt,
'public',
));
}
Future<RsaOaepPublicKeyImpl> rsaOaepPublicKey_importJsonWebKey(
Map<String, dynamic> jwk,
HashImpl hash,
) async {
return _RsaOaepPublicKeyImpl(await _importJsonWebKey(
jwk,
subtle.Algorithm(
name: _rsaOaepAlgorithmName,
hash: _getHashAlgorithm(hash),
),
_usagesEncrypt,
'public',
));
}
final class _StaticRsaOaepPrivateKeyImpl
implements StaticRsaOaepPrivateKeyImpl {
const _StaticRsaOaepPrivateKeyImpl();
@override
Future<RsaOaepPrivateKeyImpl> importPkcs8Key(
List<int> keyData, HashImpl hash) {
return rsaOaepPrivateKey_importPkcs8Key(keyData, hash);
}
@override
Future<RsaOaepPrivateKeyImpl> importJsonWebKey(
Map<String, dynamic> jwk, HashImpl hash) {
return rsaOaepPrivateKey_importJsonWebKey(jwk, hash);
}
@override
Future<(RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl)> generateKey(
int modulusLength, BigInt publicExponent, HashImpl hash) async {
final KeyPair<RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl> keyPair =
await rsaOaepPrivateKey_generateKey(
modulusLength, publicExponent, hash);
return (keyPair.privateKey, keyPair.publicKey);
}
}
final class _RsaOaepPrivateKeyImpl implements RsaOaepPrivateKeyImpl {
final subtle.JSCryptoKey _key;
_RsaOaepPrivateKeyImpl(this._key);
@override
String toString() {
return 'Instance of \'RsaOaepPrivateKeyImpl\'';
}
@override
Future<Uint8List> decryptBytes(List<int> data, {List<int>? label}) async {
return _decrypt(
label == null
? const subtle.Algorithm(name: _rsaOaepAlgorithmName)
: subtle.Algorithm(
name: _rsaOaepAlgorithmName,
label: Uint8List.fromList(label),
),
_key,
data,
);
}
@override
Future<Map<String, dynamic>> exportJsonWebKey() async {
return await _exportJsonWebKey(_key);
}
@override
Future<Uint8List> exportPkcs8Key() async {
return await _exportKey('pkcs8', _key);
}
}
final class _StaticRsaOaepPublicKeyImpl implements StaticRsaOaepPublicKeyImpl {
const _StaticRsaOaepPublicKeyImpl();
@override
Future<RsaOaepPublicKeyImpl> importSpkiKey(List<int> keyData, HashImpl hash) {
return rsaOaepPublicKey_importSpkiKey(keyData, hash);
}
@override
Future<RsaOaepPublicKeyImpl> importJsonWebKey(
Map<String, dynamic> jwk, HashImpl hash) {
return rsaOaepPublicKey_importJsonWebKey(jwk, hash);
}
}
final class _RsaOaepPublicKeyImpl implements RsaOaepPublicKeyImpl {
final subtle.JSCryptoKey _key;
_RsaOaepPublicKeyImpl(this._key);
@override
String toString() {
return 'Instance of \'RsaOaepPublicKeyImpl\'';
}
@override
Future<Uint8List> encryptBytes(List<int> data, {List<int>? label}) async {
return _encrypt(
label == null
? const subtle.Algorithm(name: _rsaOaepAlgorithmName)
: subtle.Algorithm(
name: _rsaOaepAlgorithmName,
label: Uint8List.fromList(label),
),
_key,
data,
);
}
@override
Future<Map<String, dynamic>> exportJsonWebKey() async {
return await _exportJsonWebKey(_key);
}
@override
Future<Uint8List> exportSpkiKey() async {
return await _exportKey('spki', _key);
}
}