Contact Us Forum Customers Area

DidiSoft Ltd.

Change password

<< Back to .NET examples

This example demonstrates how to change the password of a private (secret) key located in a given KeyStore file.

If we have a standalone OpenPGP private key file and want to change it’s password we can import it in the KeyStore, execute the example code below and export it back to a file.

C#

using System;
using DidiSoft;
 
class ChangeKeyPassword
{
 public void Demo()
 {
  // initialize the key store
  KeyStore ks = new KeyStore(@"DataFiles\key.store", "changeit");
 
  string privateKeyUserId = "support@didisoft.com";
  string currentPassword = "changeit";
  string newPassword = "new pass phrase";
 
  // change password
  bool keyFound = ks.ChangePrivateKeyPassword(privateKeyUserId,
						currentPassword,
						newPassword);
  if (keyFound)
  {
	Console.WriteLine("Password successfully changed.");
  }
  else
  {
	Console.WriteLine("No secret key was found with user Id = " + privateKeyUserId);
  }
 }
}

VB.NET

Imports System
Imports DidiSoft
 
Class ChangeKeyPassword
 Public Sub Demo()
  ' initialize the key store
  Dim ks As New KeyStore("DataFiles\key.store", "changeit")
 
  Dim privateKeyUserId As String = "support@didisoft.com"
  Dim currentPassword As String = "changeit"
  Dim newPassword As String = "new pass phrase"
 
  ' change password
  Dim keyFound As Boolean = _
        ks.ChangePrivateKeyPassword(privateKeyUserId, _
				    currentPassword, _
				    newPassword)
 
  If keyFound Then
	Console.WriteLine("Password successfully changed.")
  Else
	Console.WriteLine("No secret key was found with user Id = " + privateKeyUserId)
  End If
 End Sub
End Class

<< Back to .NET examples