|
|
@@ -1,452 +0,0 @@
|
|
1
|
|
-using System;
|
|
2
|
|
-using System.Collections.Generic;
|
|
3
|
|
-using System.Text;
|
|
4
|
|
-using System.IO;
|
|
5
|
|
-using System.Security.Cryptography;
|
|
6
|
|
-
|
|
7
|
|
-namespace Com.Alipay
|
|
8
|
|
-{
|
|
9
|
|
- /// <summary>
|
|
10
|
|
- /// 类名:RSAFromPkcs8
|
|
11
|
|
- /// 功能:RSA解密、签名、验签
|
|
12
|
|
- /// 详细:该类对Java生成的密钥进行解密和签名以及验签专用类,不需要修改
|
|
13
|
|
- /// 版本:2.0
|
|
14
|
|
- /// 修改日期:2011-05-10
|
|
15
|
|
- /// 说明:
|
|
16
|
|
- /// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
|
17
|
|
- /// 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
|
18
|
|
- /// </summary>
|
|
19
|
|
- public sealed class RSAFromPkcs8
|
|
20
|
|
- {
|
|
21
|
|
- /// <summary>
|
|
22
|
|
- /// 签名
|
|
23
|
|
- /// </summary>
|
|
24
|
|
- /// <param name="content">需要签名的内容</param>
|
|
25
|
|
- /// <param name="privateKey">私钥</param>
|
|
26
|
|
- /// <param name="input_charset">编码格式</param>
|
|
27
|
|
- /// <returns></returns>
|
|
28
|
|
- public static string sign(string content, string privateKey, string input_charset)
|
|
29
|
|
- {
|
|
30
|
|
- return RSASignCharSet(content, privateKey, input_charset);
|
|
31
|
|
- }
|
|
32
|
|
-
|
|
33
|
|
- public static string RSASignCharSet(string data, string privateKey, string charset)
|
|
34
|
|
- {
|
|
35
|
|
- RSACryptoServiceProvider rsaCsp = LoadCertificateString(privateKey);
|
|
36
|
|
- byte[] dataBytes = null;
|
|
37
|
|
- if (string.IsNullOrEmpty(charset))
|
|
38
|
|
- {
|
|
39
|
|
- dataBytes = Encoding.UTF8.GetBytes(data);
|
|
40
|
|
- }
|
|
41
|
|
- else
|
|
42
|
|
- {
|
|
43
|
|
- dataBytes = Encoding.GetEncoding(charset).GetBytes(data);
|
|
44
|
|
- }
|
|
45
|
|
-
|
|
46
|
|
- byte[] signatureBytes = rsaCsp.SignData(dataBytes, "SHA1");
|
|
47
|
|
-
|
|
48
|
|
- return Convert.ToBase64String(signatureBytes);
|
|
49
|
|
- }
|
|
50
|
|
-
|
|
51
|
|
- private static RSACryptoServiceProvider LoadCertificateString(string strKey)
|
|
52
|
|
- {
|
|
53
|
|
- byte[] data = null;
|
|
54
|
|
- //读取带
|
|
55
|
|
- //ata = Encoding.Default.GetBytes(strKey);
|
|
56
|
|
- data = Convert.FromBase64String(strKey);
|
|
57
|
|
- //data = GetPem("RSA PRIVATE KEY", data);
|
|
58
|
|
- try
|
|
59
|
|
- {
|
|
60
|
|
- RSACryptoServiceProvider rsa = DecodeRSAPrivateKey(data);
|
|
61
|
|
- return rsa;
|
|
62
|
|
- }
|
|
63
|
|
- catch (Exception ex)
|
|
64
|
|
- {
|
|
65
|
|
- // throw new AopException("EncryptContent = woshihaoren,zheshiyigeceshi,wanerde", ex);
|
|
66
|
|
- }
|
|
67
|
|
- return null;
|
|
68
|
|
- }
|
|
69
|
|
-
|
|
70
|
|
- private static RSACryptoServiceProvider LoadCertificateFile(string filename)
|
|
71
|
|
- {
|
|
72
|
|
- using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
|
73
|
|
- {
|
|
74
|
|
- byte[] data = new byte[fs.Length];
|
|
75
|
|
- byte[] res = null;
|
|
76
|
|
- fs.Read(data, 0, data.Length);
|
|
77
|
|
- if (data[0] != 0x30)
|
|
78
|
|
- {
|
|
79
|
|
- res = GetPem("RSA PRIVATE KEY", data);
|
|
80
|
|
- }
|
|
81
|
|
- try
|
|
82
|
|
- {
|
|
83
|
|
- RSACryptoServiceProvider rsa = DecodeRSAPrivateKey(res);
|
|
84
|
|
- return rsa;
|
|
85
|
|
- }
|
|
86
|
|
- catch (Exception ex)
|
|
87
|
|
- {
|
|
88
|
|
- }
|
|
89
|
|
- return null;
|
|
90
|
|
- }
|
|
91
|
|
- }
|
|
92
|
|
-
|
|
93
|
|
- private static byte[] GetPem(string type, byte[] data)
|
|
94
|
|
- {
|
|
95
|
|
- string pem = Encoding.UTF8.GetString(data);
|
|
96
|
|
- string header = String.Format("-----BEGIN {0}-----\\n", type);
|
|
97
|
|
- string footer = String.Format("-----END {0}-----", type);
|
|
98
|
|
- int start = pem.IndexOf(header) + header.Length;
|
|
99
|
|
- int end = pem.IndexOf(footer, start);
|
|
100
|
|
- string base64 = pem.Substring(start, (end - start));
|
|
101
|
|
-
|
|
102
|
|
- return Convert.FromBase64String(base64);
|
|
103
|
|
- }
|
|
104
|
|
-
|
|
105
|
|
-
|
|
106
|
|
-
|
|
107
|
|
- /// <summary>
|
|
108
|
|
- /// 验证签名
|
|
109
|
|
- /// </summary>
|
|
110
|
|
- /// <param name="content">需要验证的内容</param>
|
|
111
|
|
- /// <param name="signedString">签名结果</param>
|
|
112
|
|
- /// <param name="publicKey">公钥</param>
|
|
113
|
|
- /// <param name="input_charset">编码格式</param>
|
|
114
|
|
- /// <returns></returns>
|
|
115
|
|
- public static bool verify(string content, string signedString, string publicKey, string input_charset)
|
|
116
|
|
- {
|
|
117
|
|
- bool result = false;
|
|
118
|
|
-
|
|
119
|
|
- Encoding code = Encoding.GetEncoding(input_charset);
|
|
120
|
|
- byte[] Data = code.GetBytes(content);
|
|
121
|
|
- byte[] data = Convert.FromBase64String(signedString);
|
|
122
|
|
- RSAParameters paraPub = ConvertFromPublicKey(publicKey);
|
|
123
|
|
- RSACryptoServiceProvider rsaPub = new RSACryptoServiceProvider();
|
|
124
|
|
- rsaPub.ImportParameters(paraPub);
|
|
125
|
|
-
|
|
126
|
|
- SHA1 sh = new SHA1CryptoServiceProvider();
|
|
127
|
|
- result = rsaPub.VerifyData(Data, sh, data);
|
|
128
|
|
- return result;
|
|
129
|
|
- }
|
|
130
|
|
-
|
|
131
|
|
- /// <summary>
|
|
132
|
|
- /// 用RSA解密
|
|
133
|
|
- /// </summary>
|
|
134
|
|
- /// <param name="resData">待解密字符串</param>
|
|
135
|
|
- /// <param name="privateKey">私钥</param>
|
|
136
|
|
- /// <param name="input_charset">编码格式</param>
|
|
137
|
|
- /// <returns>解密结果</returns>
|
|
138
|
|
- public static string decryptData(string resData, string privateKey, string input_charset)
|
|
139
|
|
- {
|
|
140
|
|
- byte[] DataToDecrypt = Convert.FromBase64String(resData);
|
|
141
|
|
- List<byte> result = new List<byte>();
|
|
142
|
|
-
|
|
143
|
|
- for (int j = 0; j < DataToDecrypt.Length / 128; j++)
|
|
144
|
|
- {
|
|
145
|
|
- byte[] buf = new byte[128];
|
|
146
|
|
- for (int i = 0; i < 128; i++)
|
|
147
|
|
- {
|
|
148
|
|
- buf[i] = DataToDecrypt[i + 128 * j];
|
|
149
|
|
- }
|
|
150
|
|
- result.AddRange(decrypt(buf, privateKey, input_charset));
|
|
151
|
|
- }
|
|
152
|
|
- byte[] source = result.ToArray();
|
|
153
|
|
- char[] asciiChars = new char[Encoding.GetEncoding(input_charset).GetCharCount(source, 0, source.Length)];
|
|
154
|
|
- Encoding.GetEncoding(input_charset).GetChars(source, 0, source.Length, asciiChars, 0);
|
|
155
|
|
- return new string(asciiChars);
|
|
156
|
|
- }
|
|
157
|
|
-
|
|
158
|
|
- private static byte[] decrypt(byte[] data, string privateKey, string input_charset)
|
|
159
|
|
- {
|
|
160
|
|
- RSACryptoServiceProvider rsa = DecodePemPrivateKey(privateKey);
|
|
161
|
|
- SHA1 sh = new SHA1CryptoServiceProvider();
|
|
162
|
|
- return rsa.Decrypt(data, false);
|
|
163
|
|
- }
|
|
164
|
|
-
|
|
165
|
|
- /// <summary>
|
|
166
|
|
- /// 解析java生成的pem文件私钥
|
|
167
|
|
- /// </summary>
|
|
168
|
|
- /// <param name="pemstr"></param>
|
|
169
|
|
- /// <returns></returns>
|
|
170
|
|
- private static RSACryptoServiceProvider DecodePemPrivateKey(String pemstr)
|
|
171
|
|
- {
|
|
172
|
|
- byte[] pkcs8privatekey;
|
|
173
|
|
- pkcs8privatekey = Convert.FromBase64String(pemstr);
|
|
174
|
|
- if (pkcs8privatekey != null)
|
|
175
|
|
- {
|
|
176
|
|
-
|
|
177
|
|
- RSACryptoServiceProvider rsa = DecodePrivateKeyInfo(pkcs8privatekey);
|
|
178
|
|
- return rsa;
|
|
179
|
|
- }
|
|
180
|
|
- else
|
|
181
|
|
- return null;
|
|
182
|
|
- }
|
|
183
|
|
-
|
|
184
|
|
- private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8)
|
|
185
|
|
- {
|
|
186
|
|
-
|
|
187
|
|
- byte[] SeqOID = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
|
|
188
|
|
- byte[] seq = new byte[15];
|
|
189
|
|
-
|
|
190
|
|
- MemoryStream mem = new MemoryStream(pkcs8);
|
|
191
|
|
- int lenstream = (int)mem.Length;
|
|
192
|
|
- BinaryReader binr = new BinaryReader(mem); //wrap Memory Stream with BinaryReader for easy reading
|
|
193
|
|
- byte bt = 0;
|
|
194
|
|
- ushort twobytes = 0;
|
|
195
|
|
-
|
|
196
|
|
- try
|
|
197
|
|
- {
|
|
198
|
|
-
|
|
199
|
|
- twobytes = binr.ReadUInt16();
|
|
200
|
|
- if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
|
|
201
|
|
- binr.ReadByte(); //advance 1 byte
|
|
202
|
|
- else if (twobytes == 0x8230)
|
|
203
|
|
- binr.ReadInt16(); //advance 2 bytes
|
|
204
|
|
- else
|
|
205
|
|
- return null;
|
|
206
|
|
-
|
|
207
|
|
-
|
|
208
|
|
- bt = binr.ReadByte();
|
|
209
|
|
- if (bt != 0x02)
|
|
210
|
|
- return null;
|
|
211
|
|
-
|
|
212
|
|
- twobytes = binr.ReadUInt16();
|
|
213
|
|
-
|
|
214
|
|
- if (twobytes != 0x0001)
|
|
215
|
|
- return null;
|
|
216
|
|
-
|
|
217
|
|
- seq = binr.ReadBytes(15); //read the Sequence OID
|
|
218
|
|
- if (!CompareBytearrays(seq, SeqOID)) //make sure Sequence for OID is correct
|
|
219
|
|
- return null;
|
|
220
|
|
-
|
|
221
|
|
- bt = binr.ReadByte();
|
|
222
|
|
- if (bt != 0x04) //expect an Octet string
|
|
223
|
|
- return null;
|
|
224
|
|
-
|
|
225
|
|
- bt = binr.ReadByte(); //read next byte, or next 2 bytes is 0x81 or 0x82; otherwise bt is the byte count
|
|
226
|
|
- if (bt == 0x81)
|
|
227
|
|
- binr.ReadByte();
|
|
228
|
|
- else
|
|
229
|
|
- if (bt == 0x82)
|
|
230
|
|
- binr.ReadUInt16();
|
|
231
|
|
- //------ at this stage, the remaining sequence should be the RSA private key
|
|
232
|
|
-
|
|
233
|
|
- byte[] rsaprivkey = binr.ReadBytes((int)(lenstream - mem.Position));
|
|
234
|
|
- RSACryptoServiceProvider rsacsp = DecodeRSAPrivateKey(rsaprivkey);
|
|
235
|
|
- return rsacsp;
|
|
236
|
|
- }
|
|
237
|
|
-
|
|
238
|
|
- catch (Exception)
|
|
239
|
|
- {
|
|
240
|
|
- return null;
|
|
241
|
|
- }
|
|
242
|
|
-
|
|
243
|
|
- finally { binr.Close(); }
|
|
244
|
|
-
|
|
245
|
|
- }
|
|
246
|
|
-
|
|
247
|
|
-
|
|
248
|
|
- private static bool CompareBytearrays(byte[] a, byte[] b)
|
|
249
|
|
- {
|
|
250
|
|
- if (a.Length != b.Length)
|
|
251
|
|
- return false;
|
|
252
|
|
- int i = 0;
|
|
253
|
|
- foreach (byte c in a)
|
|
254
|
|
- {
|
|
255
|
|
- if (c != b[i])
|
|
256
|
|
- return false;
|
|
257
|
|
- i++;
|
|
258
|
|
- }
|
|
259
|
|
- return true;
|
|
260
|
|
- }
|
|
261
|
|
-
|
|
262
|
|
- private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey)
|
|
263
|
|
- {
|
|
264
|
|
- byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;
|
|
265
|
|
-
|
|
266
|
|
- // --------- Set up stream to decode the asn.1 encoded RSA private key ------
|
|
267
|
|
- MemoryStream mem = new MemoryStream(privkey);
|
|
268
|
|
- BinaryReader binr = new BinaryReader(mem); //wrap Memory Stream with BinaryReader for easy reading
|
|
269
|
|
- byte bt = 0;
|
|
270
|
|
- ushort twobytes = 0;
|
|
271
|
|
- int elems = 0;
|
|
272
|
|
- try
|
|
273
|
|
- {
|
|
274
|
|
- twobytes = binr.ReadUInt16();
|
|
275
|
|
- if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
|
|
276
|
|
- binr.ReadByte(); //advance 1 byte
|
|
277
|
|
- else if (twobytes == 0x8230)
|
|
278
|
|
- binr.ReadInt16(); //advance 2 bytes
|
|
279
|
|
- else
|
|
280
|
|
- return null;
|
|
281
|
|
-
|
|
282
|
|
- twobytes = binr.ReadUInt16();
|
|
283
|
|
- if (twobytes != 0x0102) //version number
|
|
284
|
|
- return null;
|
|
285
|
|
- bt = binr.ReadByte();
|
|
286
|
|
- if (bt != 0x00)
|
|
287
|
|
- return null;
|
|
288
|
|
-
|
|
289
|
|
-
|
|
290
|
|
- //------ all private key components are Integer sequences ----
|
|
291
|
|
- elems = GetIntegerSize(binr);
|
|
292
|
|
- MODULUS = binr.ReadBytes(elems);
|
|
293
|
|
-
|
|
294
|
|
- elems = GetIntegerSize(binr);
|
|
295
|
|
- E = binr.ReadBytes(elems);
|
|
296
|
|
-
|
|
297
|
|
- elems = GetIntegerSize(binr);
|
|
298
|
|
- D = binr.ReadBytes(elems);
|
|
299
|
|
-
|
|
300
|
|
- elems = GetIntegerSize(binr);
|
|
301
|
|
- P = binr.ReadBytes(elems);
|
|
302
|
|
-
|
|
303
|
|
- elems = GetIntegerSize(binr);
|
|
304
|
|
- Q = binr.ReadBytes(elems);
|
|
305
|
|
-
|
|
306
|
|
- elems = GetIntegerSize(binr);
|
|
307
|
|
- DP = binr.ReadBytes(elems);
|
|
308
|
|
-
|
|
309
|
|
- elems = GetIntegerSize(binr);
|
|
310
|
|
- DQ = binr.ReadBytes(elems);
|
|
311
|
|
-
|
|
312
|
|
- elems = GetIntegerSize(binr);
|
|
313
|
|
- IQ = binr.ReadBytes(elems);
|
|
314
|
|
-
|
|
315
|
|
- // ------- create RSACryptoServiceProvider instance and initialize with public key -----
|
|
316
|
|
- RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
|
|
317
|
|
- RSAParameters RSAparams = new RSAParameters();
|
|
318
|
|
- RSAparams.Modulus = MODULUS;
|
|
319
|
|
- RSAparams.Exponent = E;
|
|
320
|
|
- RSAparams.D = D;
|
|
321
|
|
- RSAparams.P = P;
|
|
322
|
|
- RSAparams.Q = Q;
|
|
323
|
|
- RSAparams.DP = DP;
|
|
324
|
|
- RSAparams.DQ = DQ;
|
|
325
|
|
- RSAparams.InverseQ = IQ;
|
|
326
|
|
- RSA.ImportParameters(RSAparams);
|
|
327
|
|
- return RSA;
|
|
328
|
|
- }
|
|
329
|
|
- catch (Exception)
|
|
330
|
|
- {
|
|
331
|
|
- return null;
|
|
332
|
|
- }
|
|
333
|
|
- finally { binr.Close(); }
|
|
334
|
|
- }
|
|
335
|
|
-
|
|
336
|
|
- private static int GetIntegerSize(BinaryReader binr)
|
|
337
|
|
- {
|
|
338
|
|
- byte bt = 0;
|
|
339
|
|
- byte lowbyte = 0x00;
|
|
340
|
|
- byte highbyte = 0x00;
|
|
341
|
|
- int count = 0;
|
|
342
|
|
- bt = binr.ReadByte();
|
|
343
|
|
- if (bt != 0x02) //expect integer
|
|
344
|
|
- return 0;
|
|
345
|
|
- bt = binr.ReadByte();
|
|
346
|
|
-
|
|
347
|
|
- if (bt == 0x81)
|
|
348
|
|
- count = binr.ReadByte(); // data size in next byte
|
|
349
|
|
- else
|
|
350
|
|
- if (bt == 0x82)
|
|
351
|
|
- {
|
|
352
|
|
- highbyte = binr.ReadByte(); // data size in next 2 bytes
|
|
353
|
|
- lowbyte = binr.ReadByte();
|
|
354
|
|
- byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
|
|
355
|
|
- count = BitConverter.ToInt32(modint, 0);
|
|
356
|
|
- }
|
|
357
|
|
- else
|
|
358
|
|
- {
|
|
359
|
|
- count = bt; // we already have the data size
|
|
360
|
|
- }
|
|
361
|
|
-
|
|
362
|
|
-
|
|
363
|
|
-
|
|
364
|
|
- while (binr.ReadByte() == 0x00)
|
|
365
|
|
- { //remove high order zeros in data
|
|
366
|
|
- count -= 1;
|
|
367
|
|
- }
|
|
368
|
|
- binr.BaseStream.Seek(-1, SeekOrigin.Current); //last ReadByte wasn't a removed zero, so back up a byte
|
|
369
|
|
- return count;
|
|
370
|
|
- }
|
|
371
|
|
-
|
|
372
|
|
- #region 解析.net 生成的Pem
|
|
373
|
|
- private static RSAParameters ConvertFromPublicKey(string pemFileConent)
|
|
374
|
|
- {
|
|
375
|
|
-
|
|
376
|
|
- byte[] keyData = Convert.FromBase64String(pemFileConent);
|
|
377
|
|
- if (keyData.Length < 162)
|
|
378
|
|
- {
|
|
379
|
|
- throw new ArgumentException("pem file content is incorrect.");
|
|
380
|
|
- }
|
|
381
|
|
- byte[] pemModulus = new byte[128];
|
|
382
|
|
- byte[] pemPublicExponent = new byte[3];
|
|
383
|
|
- Array.Copy(keyData, 29, pemModulus, 0, 128);
|
|
384
|
|
- Array.Copy(keyData, 159, pemPublicExponent, 0, 3);
|
|
385
|
|
- RSAParameters para = new RSAParameters();
|
|
386
|
|
- para.Modulus = pemModulus;
|
|
387
|
|
- para.Exponent = pemPublicExponent;
|
|
388
|
|
- return para;
|
|
389
|
|
- }
|
|
390
|
|
-
|
|
391
|
|
- private static RSAParameters ConvertFromPrivateKey(string pemFileConent)
|
|
392
|
|
- {
|
|
393
|
|
- byte[] keyData = Convert.FromBase64String(pemFileConent);
|
|
394
|
|
- if (keyData.Length < 609)
|
|
395
|
|
- {
|
|
396
|
|
- throw new ArgumentException("pem file content is incorrect.");
|
|
397
|
|
- }
|
|
398
|
|
-
|
|
399
|
|
- int index = 11;
|
|
400
|
|
- byte[] pemModulus = new byte[128];
|
|
401
|
|
- Array.Copy(keyData, index, pemModulus, 0, 128);
|
|
402
|
|
-
|
|
403
|
|
- index += 128;
|
|
404
|
|
- index += 2;//141
|
|
405
|
|
- byte[] pemPublicExponent = new byte[3];
|
|
406
|
|
- Array.Copy(keyData, index, pemPublicExponent, 0, 3);
|
|
407
|
|
-
|
|
408
|
|
- index += 3;
|
|
409
|
|
- index += 4;//148
|
|
410
|
|
- byte[] pemPrivateExponent = new byte[128];
|
|
411
|
|
- Array.Copy(keyData, index, pemPrivateExponent, 0, 128);
|
|
412
|
|
-
|
|
413
|
|
- index += 128;
|
|
414
|
|
- index += ((int)keyData[index + 1] == 64 ? 2 : 3);//279
|
|
415
|
|
- byte[] pemPrime1 = new byte[64];
|
|
416
|
|
- Array.Copy(keyData, index, pemPrime1, 0, 64);
|
|
417
|
|
-
|
|
418
|
|
- index += 64;
|
|
419
|
|
- index += ((int)keyData[index + 1] == 64 ? 2 : 3);//346
|
|
420
|
|
- byte[] pemPrime2 = new byte[64];
|
|
421
|
|
- Array.Copy(keyData, index, pemPrime2, 0, 64);
|
|
422
|
|
-
|
|
423
|
|
- index += 64;
|
|
424
|
|
- index += ((int)keyData[index + 1] == 64 ? 2 : 3);//412/413
|
|
425
|
|
- byte[] pemExponent1 = new byte[64];
|
|
426
|
|
- Array.Copy(keyData, index, pemExponent1, 0, 64);
|
|
427
|
|
-
|
|
428
|
|
- index += 64;
|
|
429
|
|
- index += ((int)keyData[index + 1] == 64 ? 2 : 3);//479/480
|
|
430
|
|
- byte[] pemExponent2 = new byte[64];
|
|
431
|
|
- Array.Copy(keyData, index, pemExponent2, 0, 64);
|
|
432
|
|
-
|
|
433
|
|
- index += 64;
|
|
434
|
|
- index += ((int)keyData[index + 1] == 64 ? 2 : 3);//545/546
|
|
435
|
|
- byte[] pemCoefficient = new byte[64];
|
|
436
|
|
- Array.Copy(keyData, index, pemCoefficient, 0, 64);
|
|
437
|
|
-
|
|
438
|
|
- RSAParameters para = new RSAParameters();
|
|
439
|
|
- para.Modulus = pemModulus;
|
|
440
|
|
- para.Exponent = pemPublicExponent;
|
|
441
|
|
- para.D = pemPrivateExponent;
|
|
442
|
|
- para.P = pemPrime1;
|
|
443
|
|
- para.Q = pemPrime2;
|
|
444
|
|
- para.DP = pemExponent1;
|
|
445
|
|
- para.DQ = pemExponent2;
|
|
446
|
|
- para.InverseQ = pemCoefficient;
|
|
447
|
|
- return para;
|
|
448
|
|
- }
|
|
449
|
|
- #endregion
|
|
450
|
|
-
|
|
451
|
|
- }
|
|
452
|
|
-}
|