Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

[VB6] RSA Public Key Encryption via CNG

$
0
0
Now that Windows XP has joined earlier versions of Windows as unsupported software we can feel more free to move away from legacy technologies.

Cryptography API: Next Generation is one of the new Windows features introduced in Windows Vista.


RSA Public Key Encryption

The basic concept here is that you can create an asymmetric pair of keys: a "public" key that you give to others and a "private" key you keep yourself. Other users can all encrypt messages for you using the public key, but they cannot decrypt each others' messages to you. You can decrypt the messages using your private key.


CngRsa.cls

This is a VB6 Class that uses several CNG API calls to implement basic RSA encryption. It does not implement a key container format portable between operating systems and platforms, or a message container format.

For Windows to Windows messaging the binary BLOBs can be exchanged and work just fine. For multiplatform use you would need to expand upon this.


Caution

I won't pretend to be a cryptographer or cryptography software expert. There may be weaknesses in my usage of these API calls, and there could be quite a few areas worthy of improvement.

However this might be a useful example to get you started using the CNG API for encryption and hashing.


Requirements

As noted above, CNG became available beginning in Windows Vista. There was never a redist version of the Windows libraries involved for installation into Windows XP or earlier.

You'll also need VB6.


Demo

The demo should run fine either in the IDE or compiled. Be sure to set Break on Unhandled Errors unless you need to debug the internals of the CngRsa Class.

Running the demo should be straightforward, most of it is UI management logic that should lead you through testing step by step. There are 6 "panels" selected via buttons along the top, each becoming enabled as it becomes relevant.

After generating the key pair you can view each key in hex, or enter an input message and encrypt it.

Once you have encrypted a message you can view the cipher text and decrypt it.

After this you can go back to the message input panel, clear, and enter another message to decrypt.

You can also go back and generate a new key pair.


Name:  sshot.png
Views: 57
Size:  25.5 KB

Ready to decrypt


The demo does not persist keys or messages.


Usage

Adding CngRas.cls to a new Project is easy. There is just one file (no .BAS modules, etc.). There are no dependencies beyond those that ship as part of Windows.

See the ReadMe.txt file included for some usage notes, required sequence of calls, etc.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>