A full implementation of an RSA signed INI file.
A recent task of mine was to create a license file. The goals were that the license file should be easily read as plain text, but not modified.
The solution was to create a TSignedIniFile class. If given a private and public key the INI file is read/write, this allows a computer at the issuing company to create the license file. If only a public key is provided then the INI file is read only.
When the INI file is opened as read/write and is altered, an MD5 hash is created and then encrypted using the private key. When the INI file is opened as read only, the MD5 hash is decrypted using the public key and then compared to the current hash of the file, if they do not match then an error is raised.
This implementation allows for read-only INI files for implementing licenses. The user can easily see what their license contains, but not alter it without invalidating the license.
The full source code for the unit is included below, it requires the LockBox suite from TurboPower which is freely available on SourceForge.net
To create a key pair use one of the demos that come with LockBox. Simply add a button to the demo which does PrivateKey.SaveToFile and also PublicKey.SaveToFile, I used the RSASSA project. I usually embed the public key as a resource within my application.
I would appreciate hearing from anyone who can tell me why this doesn't work with aks256 KeySizes.