@@ -301,6 +301,75 @@ private void EncryptDecryptTest(string algorithm, DerObjectIdentifier curve)
301301 }
302302 }
303303
304+
305+ private void EncryptDecryptX25519KeysTest ( )
306+ {
307+ SecureRandom random = SecureRandom . GetInstance ( "SHA1PRNG" ) ;
308+
309+ /*IAsymmetricCipherKeyPairGenerator keyGen = GeneratorUtilities.GetKeyPairGenerator(algorithm);
310+ keyGen.Init(new ECKeyGenerationParameters(curve, random));
311+
312+ AsymmetricCipherKeyPair kpEnc = keyGen.GenerateKeyPair();
313+
314+ PgpKeyPair ecdhKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.ECDH, kpEnc, DateTime.UtcNow);*/
315+ PgpPublicKeyRing publicKeyRing = new PgpPublicKeyRing ( testX25519PubKey ) ;
316+
317+ PgpSecretKeyRing secretKeyRing = new PgpSecretKeyRing ( testX25519PrivKey ) ;
318+
319+ PgpSecretKey secretKey = secretKeyRing . GetSecretKey ( 0x6c37367cd2f455c5 ) ;
320+
321+ byte [ ] text = Encoding . ASCII . GetBytes ( "hello world!" ) ;
322+
323+ PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator ( ) ;
324+ MemoryStream ldOut = new MemoryStream ( ) ;
325+ Stream pOut = lData . Open ( ldOut , PgpLiteralDataGenerator . Utf8 , PgpLiteralData . Console , text . Length , DateTime . UtcNow ) ;
326+
327+ pOut . Write ( text , 0 , text . Length ) ;
328+
329+ pOut . Close ( ) ;
330+
331+ byte [ ] data = ldOut . ToArray ( ) ;
332+
333+ MemoryStream cbOut = new MemoryStream ( ) ;
334+
335+ PgpEncryptedDataGenerator cPk = new PgpEncryptedDataGenerator ( SymmetricKeyAlgorithmTag . Cast5 , random ) ;
336+ cPk . AddMethod ( publicKeyRing . GetPublicKey ( 0x6c37367cd2f455c5 ) ) ;
337+
338+ Stream cOut = cPk . Open ( new UncloseableStream ( cbOut ) , data . Length ) ;
339+
340+ cOut . Write ( data , 0 , data . Length ) ;
341+
342+ cOut . Close ( ) ;
343+
344+ PgpObjectFactory pgpF = new PgpObjectFactory ( cbOut . ToArray ( ) ) ;
345+
346+ PgpEncryptedDataList encList = ( PgpEncryptedDataList ) pgpF . NextPgpObject ( ) ;
347+
348+ PgpPublicKeyEncryptedData encP = ( PgpPublicKeyEncryptedData ) encList [ 0 ] ;
349+
350+ Stream clear = encP . GetDataStream ( secretKey . ExtractPrivateKey ( "test" . ToCharArray ( ) ) ) ;
351+
352+ pgpF = new PgpObjectFactory ( clear ) ;
353+
354+ PgpLiteralData ld = ( PgpLiteralData ) pgpF . NextPgpObject ( ) ;
355+
356+ clear = ld . GetInputStream ( ) ;
357+ MemoryStream bOut = new MemoryStream ( ) ;
358+
359+ int ch ;
360+ while ( ( ch = clear . ReadByte ( ) ) >= 0 )
361+ {
362+ bOut . WriteByte ( ( byte ) ch ) ;
363+ }
364+
365+ byte [ ] output = bOut . ToArray ( ) ;
366+
367+ if ( ! AreEqual ( output , text ) )
368+ {
369+ Fail ( "wrong plain text in Generated packet" ) ;
370+ }
371+ }
372+
304373 private void GnuPGCrossCheck ( )
305374 {
306375 PgpSecretKeyRing secretKeyRing = new PgpSecretKeyRing ( testX25519PrivKey ) ;
@@ -359,6 +428,8 @@ public override void PerformTest()
359428 Generate ( ) ;
360429
361430 Generate25519 ( ) ;
431+
432+ EncryptDecryptX25519KeysTest ( ) ;
362433 }
363434
364435 private void DoBasicKeyRingCheck ( PgpPublicKeyRing pubKeyRing )
0 commit comments