Decrypt-data-using-private-key - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Decrypt data using private key
VB code
Dim wodCrypt1 As wodCryptCom
Dim DecryptedText As MemBlob
Dim EncryptedText As MemBlob
Dim key As Keys
Set wodCrypt1 = New wodCryptCom
Set DecryptedText = New MemBlob
Set EncryptedText = New MemBlob
Set key = New Keys

'First we will insert inside MemBlob encrypted data.
EncryptedText.FromBase64 "WP///9wqfDxuMyx/JAAAAEhhc3N0Pp4WqF/xGgA2MuA7apt" & _
"vjHfIAOEyYDny7QNj0PnHjHatjG3pr/UNq2o+5VjQL+6MDgS1pyVIfgLEK1YGtjDK0O/7Eav" & _
"JWSEYTSGju+OBP4C9bdyIZfI9UWtBJ2meRTttZMEaW09mqexVU4ETU91IWYedSENTgabOxLkn"

'Then we need to load RSA or DSA private key from file using wodKeys component.
'wodKeys component is included in wodCrypt ActiveX component.
key.Load "c:\rsa_private.txt"

'Now we will decrypt data.
wodCrypt1.Type = RSA
wodCrypt1.Padding = PadPKCS7
'We need private key for decryption.
wodCrypt1.SecretKey = key
wodCrypt1.Decrypt EncryptedText, DecryptedText

Debug.Print DecryptedText.Text
VB.NET code
Dim wodCrypt1 As WODCRYPTCOMLib.wodCryptCom
Dim DecryptedText As WODCRYPTCOMLib.MemBlob
Dim EncryptedText As WODCRYPTCOMLib.MemBlob
Dim key As wodKeys.Keys
wodCrypt1 = New WODCRYPTCOMLib.wodCryptCom
DecryptedText = New WODCRYPTCOMLib.MemBlob
EncryptedText = New WODCRYPTCOMLib.MemBlob
key = New wodKeys.Keys

'First we will insert inside MemBlob encrypted data.
EncryptedText.FromBase64("WP///9wqfDxuMyx/JAAAAEhhc3N0Pp4WqF/xGgA2MuA7apt" & _
"vjHfIAOEyYDny7QNj0PnHjHatjG3pr/UNq2o+5VjQL+6MDgS1pyVIfgLEK1YGtjDK0O/7Eav" & _
"JWSEYTSGju+OBP4C9bdyIZfI9UWtBJ2meRTttZMEaW09mqexVU4ETU91IWYedSENTgabOxLkn")

'Then we need to load RSA or DSA private key from file using wodKeys component.
'wodKeys component is included in wodCrypt ActiveX component.
key.Load("c:\rsa_private.txt")

'Now we will decrypt data.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.RSA
wodCrypt1.Padding = WODCRYPTCOMLib.CryptoPadding.PadPKCS7
'We need private key for decryption.
wodCrypt1.SecretKey = key
wodCrypt1.Decrypt(EncryptedText, DecryptedText)

Console.WriteLine(DecryptedText.Text)
C# code
WODCRYPTCOMLib.wodCryptCom wodCrypt1;
WODCRYPTCOMLib.MemBlob DecryptedText;
WODCRYPTCOMLib.MemBlob EncryptedText;
wodKeys.Keys key;
wodCrypt1 = new WODCRYPTCOMLib.wodCryptCom();
DecryptedText = new WODCRYPTCOMLib.MemBlob();
EncryptedText = new WODCRYPTCOMLib.MemBlob();
key = new wodKeys.Keys();

DecryptedText.Text = "this is data that we want to encrypt";

//First we will insert inside MemBlob encrypted data.
EncryptedText.FromBase64("WP///9wqfDxuMyx/JAAAAEhhc3N0Pp4WqF/xGgA2MuA7apt" + 
"vjHfIAOEyYDny7QNj0PnHjHatjG3pr/UNq2o+5VjQL+6MDgS1pyVIfgLEK1YGtjDK0O/7Eav" + 
"JWSEYTSGju+OBP4C9bdyIZfI9UWtBJ2meRTttZMEaW09mqexVU4ETU91IWYedSENTgabOxLkn");

//Then we need to load RSA or DSA private key from file using wodKeys component.
//wodKeys component is included in wodCrypt ActiveX component.
key.Load("c:\\rsa_private.txt", null);

//Now we will decrypt data.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.RSA;
wodCrypt1.Padding = WODCRYPTCOMLib.CryptoPadding.PadPKCS7;
//We need private key for decryption.
wodCrypt1.SecretKey = key;
wodCrypt1.Decrypt((WODCRYPTCOMLib.Blob)EncryptedText, (WODCRYPTCOMLib.Blob)DecryptedText);

Console.WriteLine(DecryptedText.Text);