My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
using System;
using System.IO;

using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Bcpg;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.IO;

using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;
using O2.DotNetWrappers.Windows;

//O2Ref:itextsharp.dll
//O2Ref:O2_DotNetWrappers.dll
//O2Ref:O2_Kernel.dll

namespace O2.XRules.Database.APIs
{

// parts of these CreateKey methods are based on the examples from http://downloads.bouncycastle.org/csharp/bccrypto-net-1.6.1-src.zip

public class API_OpenPgp
{
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public string Identity { get; set; }
public string PassPhrase { get; set; }

public API_OpenPgp()
{
}


public static API_OpenPgp load(string file)
{
return file.deserialize<API_OpenPgp>();
}
}

public static class API_OpenPgp_ExtensionMethods
{
public static API_OpenPgp openPgp(this string pathToOpenPgpFile)
{
return pathToOpenPgpFile.load<API_OpenPgp>();
}

public static string save(this API_OpenPgp openPgp)
{
return openPgp.save("_API_OpenPgp.xml".tempFile());
}

public static string save(this API_OpenPgp openPgp, string pathToSave)
{
if (openPgp.serialize(pathToSave))
return pathToSave;
return "";
}

public static API_OpenPgp moveFilesToFolder(this API_OpenPgp openPgp, string targetFolder)
{
targetFolder.createDir(); // make sure it exists
openPgp.PrivateKey = Files.Copy(openPgp.PrivateKey,targetFolder);
openPgp.PublicKey = Files.Copy(openPgp.PublicKey,targetFolder);
return openPgp;
}

public static API_OpenPgp fixOpenPgpKeysPaths(this API_OpenPgp openPgp, string file)
{
// see if we need to resolve the paths
if (openPgp.PrivateKey.fileExists().isFalse())
{
var localPrivateKey = file.directoryName().pathCombine(openPgp.PrivateKey);
if (localPrivateKey.fileExists())
openPgp.PrivateKey = localPrivateKey;
}

if (openPgp.PublicKey.fileExists().isFalse())
{
var localPublicKey = file.directoryName().pathCombine(openPgp.PublicKey);
if (localPublicKey.fileExists())
openPgp.PublicKey = localPublicKey;
}
return openPgp;
}

}


public static class API_OpenPgp_ExtensionMethods_CreateKey
{
public static string defaultSufix_PrivateKey = "_privateKey.asc";
public static string defaultSufix_PublicKey = "_publicKey.asc";

public static string createKey(this API_OpenPgp openPgp)
{
string random_Identity = 12.randomLetters();
string random_passPhrase = 64.randomLetters();
return openPgp.createKey(random_Identity, random_passPhrase);
}

public static string createKey(this API_OpenPgp openPgp, string identity)
{
string random_passPhrase = 64.randomLetters();
return openPgp.createKey(identity, random_passPhrase);
}

public static string createKey(this API_OpenPgp openPgp, string identity, string passPhrase)
{
return openPgp.createKey(identity, passPhrase, "".tempDir());
}

public static string createKey(this API_OpenPgp openPgp, string identity, string passPhrase, string targetFolder)
{
targetFolder.createDir(); // make sure it is created
string pathTo_PrivateKey = targetFolder.pathCombine("{0}_{1}".format(identity, defaultSufix_PrivateKey));
string pathTo_PublicKey = targetFolder.pathCombine("{0}_{1}".format(identity, defaultSufix_PublicKey));
return openPgp.createKey(identity,passPhrase, pathTo_PrivateKey, pathTo_PublicKey);
}

public static string createKey(this API_OpenPgp openPgp, string identity, string passPhrase, string pathTo_PrivateKey, string pathTo_PublicKey)
{
if (identity.valid().isFalse())
{
"[API_OpenPgp] there was no value provided for the mandatory field: PGP Identity".error();
return null;
}
IAsymmetricCipherKeyPairGenerator kpg = GeneratorUtilities.GetKeyPairGenerator("RSA");

kpg.Init(new RsaKeyGenerationParameters(
//BigInteger.ValueOf(0x10001), new SecureRandom(), 1024, 25));
BigInteger.ValueOf(0x10001), new SecureRandom(), 2048, 25));

AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();

Stream privateKey, publicKey;
privateKey = File.Create(pathTo_PrivateKey);
publicKey = File.Create(pathTo_PublicKey);

new RsaKeyRingGenerator().ExportKeyPair(privateKey, publicKey, kp.Public, kp.Private, identity, passPhrase.ToCharArray(), true);

privateKey.Close();
publicKey.Close();

openPgp.PrivateKey = pathTo_PrivateKey;
openPgp.PublicKey = pathTo_PublicKey;
openPgp.Identity = identity;
openPgp.PassPhrase = passPhrase;

var openPgpFile = pathTo_PublicKey.directoryName().pathCombine("{0}_OpenPgp.xml".format(identity));
openPgp.save(openPgpFile);
"[API_OpenPgp] Pgp mappings for identity '{0}' saved to: {0}".debug(openPgpFile);
return openPgpFile;
}

public sealed class RsaKeyRingGenerator
{
public RsaKeyRingGenerator()
{
}

public void ExportKeyPair(
Stream secretOut,
Stream publicOut,
AsymmetricKeyParameter publicKey,
AsymmetricKeyParameter privateKey,
string identity,
char[] passPhrase,
bool armor)
{
if (armor)
{
secretOut = new ArmoredOutputStream(secretOut);
}

PgpSecretKey secretKey = new PgpSecretKey(
PgpSignature.DefaultCertification,
PublicKeyAlgorithmTag.RsaGeneral,
publicKey,
privateKey,
DateTime.UtcNow,
identity,
SymmetricKeyAlgorithmTag.Cast5,
passPhrase,
null,
null,
new SecureRandom()
);

secretKey.Encode(secretOut);

if (armor)
{
secretOut.Close();
publicOut = new ArmoredOutputStream(publicOut);
}

PgpPublicKey key = secretKey.PublicKey;

key.Encode(publicOut);

if (armor)
{
publicOut.Close();
}
}
}
}


public static class API_OpenPgp_ExtensionMethods_EncryptText
{

public static string pgp_EncryptText(this string textToEncrypt, string pathToOpenPgpFile)
{
if (pathToOpenPgpFile.fileExists())
{
var openPgp = pathToOpenPgpFile.openPgp();
openPgp.fixOpenPgpKeysPaths(pathToOpenPgpFile);
return openPgp.encryptText(textToEncrypt);
}
return null;
}

public static string encryptText(this API_OpenPgp openPgp, string textToEncrypt)
{
try
{
if (openPgp.notNull())
{
var tempFile = textToEncrypt.save();
var resultTempFile = openPgp.encryptFile(tempFile);
var result = resultTempFile.fileContents();
Files.deleteFile(tempFile);
Files.deleteFile(resultTempFile);
return result;
}
}
catch(Exception ex)
{
ex.log("[API_OpenPgp] in EncryptText");
}
return null;
}

public static string decryptText(this API_OpenPgp openPgp, string textToEncrypt)
{
try
{
if (openPgp.notNull())
{
var tempFile = textToEncrypt.saveWithExtension(".asc");
"tempFile: {0}".info(tempFile);
var resultTempFile = openPgp.decryptFile(tempFile);
var result = resultTempFile.fileContents();
Files.deleteFile(tempFile);
Files.deleteFile(resultTempFile);
return result;
}
}
catch(Exception ex)
{
ex.log("[API_OpenPgp] in DecryptText");
}
return null;

}
}

public static class API_OpenPgp_ExtensionMethods_EncryptFile
{
public static string encryptFile(this API_OpenPgp openPgp, string fileToEncrypt)
{
try
{
var publicKey = openPgp.PublicKey;
if (publicKey.fileExists().isFalse())
publicKey = PublicDI.CurrentScript.directoryName().pathCombine(publicKey);
if (fileToEncrypt.fileExists().isFalse())
{
"[API_OpenPgp] in API_OpenPgp signFile, the provided file to encrypt doesn't exist: {0}".error(fileToEncrypt);
return "";
}
var keyIn = File.OpenRead(publicKey);
var pathToEncryptedFile = fileToEncrypt + ".asc";
var fos = File.Create(pathToEncryptedFile);
EncryptFile(fos, fileToEncrypt, OpenPgp_HelperMethods.ReadPublicKey(keyIn), true, true);
fos.Close();
return pathToEncryptedFile;
}
catch(Exception ex)
{
ex.log("[API_OpenPgp] in encryptFile");
return null;
}

}

private static void EncryptFile(
Stream outputStream,
string fileName,
PgpPublicKey encKey,
bool armor,
bool withIntegrityCheck)
{
if (armor)
{
outputStream = new ArmoredOutputStream(outputStream);
}

try
{
MemoryStream bOut = new MemoryStream();

PgpCompressedDataGenerator comData = new PgpCompressedDataGenerator(
CompressionAlgorithmTag.Zip);

PgpUtilities.WriteFileToLiteralData(
comData.Open(bOut),
PgpLiteralData.Binary,
new FileInfo(fileName));

comData.Close();

PgpEncryptedDataGenerator cPk = new PgpEncryptedDataGenerator(
SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck, new SecureRandom());

cPk.AddMethod(encKey);

byte[] bytes = bOut.ToArray();

Stream cOut = cPk.Open(outputStream, bytes.Length);

cOut.Write(bytes, 0, bytes.Length);

cOut.Close();

if (armor)
{
outputStream.Close();
}
}
catch (PgpException e)
{
e.log("[API_OpenPgp] in EncryptFile");
/* Console.Error.WriteLine(e);

Exception underlyingException = e.InnerException;
if (underlyingException != null)
{
Console.Error.WriteLine(underlyingException.Message);
Console.Error.WriteLine(underlyingException.StackTrace);
}*/
}
}
}


public static class API_OpenPgp_ExtensionMethods_DecryptFile
{

public static string decryptFile(this API_OpenPgp openPgp, string fileToDecrypt)
{
"In Decrypt step".info();
var privateKey = openPgp.PrivateKey;
if (privateKey.fileExists().isFalse())
privateKey = PublicDI.CurrentScript.directoryName().pathCombine(privateKey);
var passPhrase = openPgp.PassPhrase;
if (passPhrase.valid().isFalse())
passPhrase = "What is the passphase to unlock the Private Key?".askUser();

if (fileToDecrypt.fileExists().isFalse())
{
"in API_OpenPgp signFile, the provided file to decrypt doesn't exist: {0}".error(fileToDecrypt);
return "";
}
var keyIn = File.OpenRead(privateKey);
var fin = File.OpenRead(fileToDecrypt);
var originalExtension = Path.GetFileNameWithoutExtension(fileToDecrypt).extension();
if (originalExtension.valid().isFalse())
originalExtension = ".out";
var pathToDecryptedFile = fileToDecrypt + originalExtension; // new FileInfo(args[1]).Name + ".out"
DecryptFile(fin, keyIn, passPhrase.ToCharArray(), pathToDecryptedFile);
fin.Close();
keyIn.Close();
//var pathToEncryptedFile = fileToEncrypt + ".asc";
//var fos = File.Create(pathToEncryptedFile);
//EncryptFile(fos, fileToEncrypt, OpenPgp_HelperMethods.ReadPublicKey(keyIn), true, true);
//fos.Close();
return pathToDecryptedFile;
}

/**
* decrypt the passed in message stream
*/
private static void DecryptFile(
Stream inputStream,
Stream keyIn,
char[] passwd,
string pathToDecryptedFile) //DC
{
try
{
inputStream = PgpUtilities.GetDecoderStream(inputStream);

try
{
PgpObjectFactory pgpF = new PgpObjectFactory(inputStream);
PgpEncryptedDataList enc;

PgpObject o = pgpF.NextPgpObject();
//
// the first object might be a PGP marker packet.
//

if (o is PgpEncryptedDataList)
{
enc = (PgpEncryptedDataList)o;
}
else
{
enc = (PgpEncryptedDataList)pgpF.NextPgpObject();
}

//
// find the secret key
//
PgpPrivateKey sKey = null;
PgpPublicKeyEncryptedData pbe = null;
PgpSecretKeyRingBundle pgpSec = new PgpSecretKeyRingBundle(
PgpUtilities.GetDecoderStream(keyIn));

foreach (PgpPublicKeyEncryptedData pked in enc.GetEncryptedDataObjects())
{
sKey = OpenPgp_HelperMethods.FindSecretKey(pgpSec, pked.KeyId, passwd);

if (sKey != null)
{
pbe = pked;
break;
}
}

if (sKey == null)
{
throw new ArgumentException("secret key for message not found.");
}

Stream clear = pbe.GetDataStream(sKey);

PgpObjectFactory plainFact = new PgpObjectFactory(clear);

PgpObject message = plainFact.NextPgpObject();

PgpObjectFactory pgpFact = null;

if (message is PgpCompressedData)
{
PgpCompressedData cData = (PgpCompressedData)message;
pgpFact = new PgpObjectFactory(cData.GetDataStream());

message = pgpFact.NextPgpObject();
}

if (message is PgpOnePassSignatureList) // DC
{ // DC
message = pgpFact.NextPgpObject(); // DC
} // DC

if (message is PgpLiteralData)
{
PgpLiteralData ld = (PgpLiteralData)message;

Stream fOut = File.Create(pathToDecryptedFile); //DC (modified to use the name provided in pathToDecryptedFile
Stream unc = ld.GetInputStream();
Streams.PipeAll(unc, fOut);
fOut.Close();
}
else if (message is PgpOnePassSignatureList)
{
"[API_OpenPgp][DecryptFile] encrypted message contains a signed message - not literal data.".error();
return ;
}
else
{
"[API_OpenPgp][DecryptFile] message is not a simple encrypted file - type unknown.".error();
return;
}

if (pbe.IsIntegrityProtected())
{
if (!pbe.Verify())
{
"[API_OpenPgp][DecryptFile] message failed integrity check".error();
}
else
{
"[API_OpenPgp][DecryptFile] message integrity check passed".debug();
}
}
else
{
"[API_OpenPgp][DecryptFile] no message integrity check".error();
}
}
catch (PgpException e)
{
e.log("[API_OpenPgp] in DecryptFile: " + e.StackTrace );

/*Console.Error.WriteLine(e);

Exception underlyingException = e.InnerException;
if (underlyingException != null)
{
Console.Error.WriteLine(underlyingException.Message);
Console.Error.WriteLine(underlyingException.StackTrace);
}*/
}
}
catch (Exception ex)
{
ex.log("[API_OpenPgp] in DecryptFile : " + ex.StackTrace );
}
}

}

//need to check this code out to make sure it is working as expected
/*
public static class API_OpenPgp_ExtensionMethods_SignFile
{

public static string signFile(this API_OpenPgp openPgp, string fileToSign)
{
if (fileToSign.fileExists().isFalse())
{
"in API_OpenPgp signFile, the provided file to sign doesn't exist: {0}".error(fileToSign);
return "";
}
var keyIn = File.OpenRead(openPgp.PrivateKey);
var pathToSignedFile = fileToSign + ".asc";
var fos = File.Create(pathToSignedFile);
SignFile(fileToSign, keyIn, fos, openPgp.PassPhrase.ToCharArray(), true, true);
fos.Close();
return pathToSignedFile;
}

//TODO: this part is not working with the file created by the SignFile
public static API_OpenPgp verifyFile(this API_OpenPgp openPgp, string fileToVerify)
{
if (fileToVerify.fileExists().isFalse())
"in API_OpenPgp verifyFile, the provided file to verify doesn't exist: {0}".error(fileToVerify);
else
{
var keyIn = File.OpenRead(openPgp.PublicKey);
var fos = File.Create(fileToVerify);
if (VerifyFile(fos, keyIn))
"[API_OpenPgp] signature verified.".debug();
else
"[API_OpenPgp] signature verification failed.".error();

fos.Close();
}
return openPgp;
}


private static bool VerifyFile(Stream inputStream,Stream keyIn)
{
inputStream = PgpUtilities.GetDecoderStream(inputStream);

PgpObjectFactory pgpFact = new PgpObjectFactory(inputStream);
PgpCompressedData c1 = (PgpCompressedData) pgpFact.NextPgpObject();
pgpFact = new PgpObjectFactory(c1.GetDataStream());

PgpOnePassSignatureList p1 = (PgpOnePassSignatureList) pgpFact.NextPgpObject();
PgpOnePassSignature ops = p1[0];

PgpLiteralData p2 = (PgpLiteralData) pgpFact.NextPgpObject();
Stream dIn = p2.GetInputStream();
PgpPublicKeyRingBundle pgpRing = new PgpPublicKeyRingBundle(PgpUtilities.GetDecoderStream(keyIn));
PgpPublicKey key = pgpRing.GetPublicKey(ops.KeyId);
Stream fos = File.Create(p2.FileName);

ops.InitVerify(key);

int ch;
while ((ch = dIn.ReadByte()) >= 0)
{
ops.Update((byte)ch);
fos.WriteByte((byte) ch);
}
fos.Close();

PgpSignatureList p3 = (PgpSignatureList)pgpFact.NextPgpObject();
PgpSignature firstSig = p3[0];
if (ops.Verify(firstSig))
return true;
else
return false;
}

private static void SignFile(
string fileName,
Stream keyIn,
Stream outputStream,
char[] pass,
bool armor,
bool compress)
{
if (armor)
{
outputStream = new ArmoredOutputStream(outputStream);
}

PgpSecretKey pgpSec = OpenPgp_HelperMethods.ReadSecretKey(keyIn);
PgpPrivateKey pgpPrivKey = pgpSec.ExtractPrivateKey(pass);
PgpSignatureGenerator sGen = new PgpSignatureGenerator(pgpSec.PublicKey.Algorithm, HashAlgorithmTag.Sha1);

sGen.InitSign(PgpSignature.BinaryDocument, pgpPrivKey);
foreach (string userId in pgpSec.PublicKey.GetUserIds())
{
PgpSignatureSubpacketGenerator spGen = new PgpSignatureSubpacketGenerator();
spGen.SetSignerUserId(false, userId);
sGen.SetHashedSubpackets(spGen.Generate());
// Just the first one!
break;
}

Stream cOut = outputStream;
PgpCompressedDataGenerator cGen = null;
if (compress)
{
cGen = new PgpCompressedDataGenerator(CompressionAlgorithmTag.ZLib);

cOut = cGen.Open(cOut);
}

BcpgOutputStream bOut = new BcpgOutputStream(cOut);

sGen.GenerateOnePassVersion(false).Encode(bOut);

FileInfo file = new FileInfo(fileName);
PgpLiteralDataGenerator lGen = new PgpLiteralDataGenerator();
Stream lOut = lGen.Open(bOut, PgpLiteralData.Binary, file);
FileStream fIn = file.OpenRead();
int ch = 0;

while ((ch = fIn.ReadByte()) >= 0)
{
lOut.WriteByte((byte) ch);
sGen.Update((byte)ch);
}

fIn.Close();
lGen.Close();

sGen.Generate().Encode(bOut);

if (cGen != null)
{
cGen.Close();
}

if (armor)
{
outputStream.Close();
}
}
}*/


public class OpenPgp_HelperMethods
{
public static PgpSecretKey ReadSecretKey(
Stream inputStream)
{
inputStream = PgpUtilities.GetDecoderStream(inputStream);

PgpSecretKeyRingBundle pgpSec = new PgpSecretKeyRingBundle(inputStream);

//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//

foreach (PgpSecretKeyRing kRing in pgpSec.GetKeyRings())
{
foreach (PgpSecretKey k in kRing.GetSecretKeys())
{
if (k.IsSigningKey)
{
return k;
}
}
}

throw new ArgumentException("Can't find signing key in key ring.");
}

public static PgpPublicKey ReadPublicKey(
Stream inputStream)
{
inputStream = PgpUtilities.GetDecoderStream(inputStream);

PgpPublicKeyRingBundle pgpPub = new PgpPublicKeyRingBundle(inputStream);

//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//

//
// iterate through the key rings.
//

foreach (PgpPublicKeyRing kRing in pgpPub.GetKeyRings())
{
foreach (PgpPublicKey k in kRing.GetPublicKeys())
{
if (k.IsEncryptionKey)
{
return k;
}
}
}

throw new ArgumentException("Can't find encryption key in key ring.");
}

/**
* Search a secret key ring collection for a secret key corresponding to
* keyId if it exists.
*
* @param pgpSec a secret key ring collection.
* @param keyId keyId we want.
* @param pass passphrase to decrypt secret key with.
* @return
*/
public static PgpPrivateKey FindSecretKey(
PgpSecretKeyRingBundle pgpSec,
long keyId,
char[] pass)
{
PgpSecretKey pgpSecKey = pgpSec.GetSecretKey(keyId);

if (pgpSecKey == null)
{
return null;
}

return pgpSecKey.ExtractPrivateKey(pass);
}

}
}

Change log

r807 by di...@ddplus.net on Apr 16, 2011   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r729 by di...@ddplus.net on Oct 13, 2010   Diff
[No log message]
r728 by di...@ddplus.net on Oct 11, 2010   Diff
[No log message]
r568 by di...@ddplus.net on Jul 4, 2010   Diff
[No log message]
All revisions of this file

File info

Size: 24915 bytes, 761 lines
Powered by Google Project Hosting