Net Encryption Library
EcdhPrivateKey Constructor()
Example 






KellermanSoftware.NetEncryptionLibrary.ECDH Namespace > EcdhPrivateKey Class > EcdhPrivateKey Constructor : EcdhPrivateKey Constructor()
Create a new secret key
Syntax
'Declaration
 
Public Function New()
'Usage
 
Dim instance As New EcdhPrivateKey()
public EcdhPrivateKey()
public EcdhPrivateKey(); 
public function EcdhPrivateKey();
public: EcdhPrivateKey();
public:
EcdhPrivateKey();
Example
//Create private keys for each person
EcdhPrivateKey johnsSecretKey = new EcdhPrivateKey();
EcdhPrivateKey janesSecretKey = new EcdhPrivateKey();
 
//Get the public keys
string johnsPublicKey = johnsSecretKey.GetPublicKey().PublicKeyString;
string janesPublicKey = janesSecretKey.GetPublicKey().PublicKeyString;
 
Console.WriteLine("John's Public Key");
Console.WriteLine(johnsPublicKey);
 
Console.WriteLine("Janes's Public Key");
Console.WriteLine(janesPublicKey);
 
//Get the shared key (these will calculate the same)
string johnsSharedKey = johnsSecretKey.GetSharedSecretKey(new EcdhPublicKey(janesPublicKey)).SharedKeyString;
string janesSharedKey = janesSecretKey.GetSharedSecretKey(new EcdhPublicKey(johnsPublicKey)).SharedKeyString;
 
Console.WriteLine("John's Shared Key");
Console.WriteLine(johnsSharedKey);
 
Console.WriteLine("Janes's Shared Key");
Console.WriteLine(janesSharedKey);
 
Encryption encryption = new Encryption(); //Trial Mode
//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode
 
const string unencryptedString = "This is the input";
Console.WriteLine("The unencrypted string: {0}", unencryptedString);
 
string encryptedString = encryption.EncryptString(EncryptionProvider.Rijndael, johnsSharedKey, unencryptedString);
Console.WriteLine("The encrypted string: {0}", encryptedString);
 
string decryptedString = encryption.DecryptString(EncryptionProvider.Rijndael, janesSharedKey, encryptedString);
Console.WriteLine("The decrypted string: {0}", decryptedString);
'Create private keys for each person
Dim johnsSecretKey As New EcdhPrivateKey()
Dim janesSecretKey As New EcdhPrivateKey()
 
'Get the public keys
Dim johnsPublicKey As String = johnsSecretKey.GetPublicKey().PublicKeyString
Dim janesPublicKey As String = janesSecretKey.GetPublicKey().PublicKeyString
 
Console.WriteLine("John's Public Key")
Console.WriteLine(johnsPublicKey)
 
Console.WriteLine("Janes's Public Key")
Console.WriteLine(janesPublicKey)
 
'Get the shared key (these will calculate the same)
Dim johnsSharedKey As String = johnsSecretKey.GetSharedSecretKey(New EcdhPublicKey(janesPublicKey)).SharedKeyString
Dim janesSharedKey As String = janesSecretKey.GetSharedSecretKey(New EcdhPublicKey(johnsPublicKey)).SharedKeyString
 
Console.WriteLine("John's Shared Key")
Console.WriteLine(johnsSharedKey)
 
Console.WriteLine("Janes's Shared Key")
Console.WriteLine(janesSharedKey)
 
Dim encryption As New Encryption() 'Trial Mode
'Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode
 
Const unencryptedString As String = "This is the input"
Console.WriteLine("The unencrypted string: {0}", unencryptedString)
 
Dim encryptedString As String = encryption.EncryptString(EncryptionProvider.Rijndael, johnsSharedKey, unencryptedString)
Console.WriteLine("The encrypted string: {0}", encryptedString)
 
Dim decryptedString As String = encryption.DecryptString(EncryptionProvider.Rijndael, janesSharedKey, encryptedString)
Console.WriteLine("The decrypted string: {0}", decryptedString)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EcdhPrivateKey Class
EcdhPrivateKey Members
Overload List