web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

not able to access PGP keys in Class added to vault as Secret

(1) ShareShare
ReportReport
Posted on by 351
Hi All,
 
I have uploaded PGP keys (Public key, Private key and passphrase) in Azure Keyvault. I am able to fetch the key values in F&O by below code:
  select keyVaultParameters where keyVaultParameters.Name == 'XXXX-KV';

  //passphrase
  select  certificateTablepass where certificateTablepass.KeyVaultRef==keyVaultParameters.RecId
      && certificateTablepass.Name == 'XXXXPGPPassphrase';
  
  str passphrase = KeyVaultCertificateHelper::getManualSecretValue(certificateTablepass.RecId);


  //privatekey
  select  certificateTablepriv where certificateTablepriv.KeyVaultRef==keyVaultParameters.RecId
       && certificateTablepriv.Name == 'XXXPGPPrivate';
  
  str passprivatekey = KeyVaultCertificateHelper::getManualSecretValue(certificateTablepriv.RecId);

  //publickey
  select  certificateTablepub where certificateTablepub.KeyVaultRef==keyVaultParameters.RecId
       && certificateTablepub.Name == 'XXXXPGPPublic';
  
  str passpublickey = KeyVaultCertificateHelper::getManualSecretValue(certificateTablepub.RecId);
 
 
Now in my dll project im trying to get the private keys , tried reading them to a Memory stream to create 

                            PgpPublicKeyRingBundle publicKeyRingBundle = new PgpPublicKeyRingBundle(stream);
                PublicKey = GetFirstPublicKey(publicKeyRingBundle);
 
 
But it is throwing error. Is it correct way or is there something easier to access the keys , create them as PGPublic Private keys.
 
Please help.
 
Thanks,
Priya
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    What is throwing an error? Assuming it's in your .Net assembly, what kind of exception did it throw?
    Can you share the exception message? 
     
  • PriyaDutta Profile Picture
    351 on at
    Hi Jones,
     
    Im getting the below error 
     
     
    Trying to convert the string to MemoryStream. Tried from F&O and passed it to Dll. I also tried to create the stream here in .net but same error message comes.
     
    Is there a better way ?
     
    Thanks.
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    Ho do you create the MemoryStream?
    I have found an example in the standard application:
     
  • PriyaDutta Profile Picture
    351 on at
    Hi Jonas,
     
    I am creating a byte array and passing from F&O
    str passpublickey = KeyVaultCertificateHelper::getManualSecretValue(certificateTablepub.RecId);
    System.Byte[]                 passpublickeybyte;
    
    System.Text.Encoding    passpublickeyencoding = System.Text.Encoding::get_UTF8();
    
    passpublickeybyte        =  passpublickeyencoding.GetBytes(passpublickey);
    
    
     outputStream1 = obj.OutputEncryptStream(stream,stream,passpublickeybyte,passprivatekeybyte,passphrase);
    After that in .net class i am writing the below code
     
     public MemoryStream OutputEncryptStream(MemoryStream inputstream, MemoryStream outputStream, System.Byte[] publicbyte, System.Byte[] privatebyte, string passphrase)
     {
    
     MemoryStream publickeyStream = new MemoryStream(publicbyte);
     // PGPKeyPair keyPair = new PGPKeyPair(publickeyStream);
      Stream inputStream = PgpUtilities.GetDecoderStream(publickeyStream);
        PgpPublicKeyRingBundle publicKeyRingBundle = new PgpPublicKeyRingBundle(inputStream);
      PublicKey = GetFirstPublicKey(publicKeyRingBundle);
     
     
     
  • Martin Dráb Profile Picture
    240,854 Most Valuable Professional on at
    The exception says that the stream has already been closed (disposed). It happens at the end of a 'using' block or when Close() or Dispose() is called explicitly. Look for these things in your code.
     
    It's strange that code of OutputEncryptStream() you've shared with us below doesn't match the code you executed when you got the error (as the screenshot shows). There you got publickeyStream as a method parameter, and it was this stream that was closed.
     
    It'll help a lot if you share the right code with us.
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    Can you upload the latest source code? 
    It's difficult to help if we cannot see it. 
     
    If it gives you issues uploading the source to the forum, you can use a GitHub gist.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 523 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 408 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 354

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans