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