- You are here:
- Home
- CodeXchange
- All
- PowerBuilder
- RS256 Encryption through .Net Assembly import
RS256 Encryption through .Net Assembly import
- Bruce Armstrong
- Code Author
- Offline
Less
More
- Posts: 55
4 years 1 week ago - 9 months 3 weeks ago #308
by Bruce Armstrong
This message has an attachment file.
Bruce Armstrong created the code: RS256 Encryption through .Net Assembly import
PowerBuilder demo code and SnapDevelop projects for two different .Net Assemblies that does RS256 ( RSA with SHA256 ) encryption. You can use either a PKCS#8 or PKCS#1 private key. PowerBuilder generates the latter when you use AsymmetricGenerateKey. Either way, you need to provide the non-Base64 prefix ( the part that contains "BEGIN RSA PRIVATE KEY" for PKCS#8 and "BEGIN PRIVATE KEY" for PKCS#1 ) so that the assembly can determine which key type it's working with.
The first assembly (RSASigning) uses Microsoft classes to handle the RSA encryption. It takes advantage of functions added in 3.1 of .Net Core, so it won't work if you have an older version of .Net Core installed. It takes the already SHA256 hashed data in Base64 format and returns the encrypted data in Base64 format. It was designed to allow PowerBuilder do as much of the work as possible, and just do the part that PowerBuilder doesn't currently do. The AsymetricEncrypt function in CrypterObjed does RSA-SHA1, not RSA- SHA256.
The second assembly (RSASigning2) uses Bouncy Castle classes and is dependent on the Bouncy Class assembly included. I couldn't find a way to make Bouncy do just the RSA encryption without also doing the hashing, so it takes the data as a raw string and does both the SHA256 hashing and the RSA encryption.
The first assembly (RSASigning) uses Microsoft classes to handle the RSA encryption. It takes advantage of functions added in 3.1 of .Net Core, so it won't work if you have an older version of .Net Core installed. It takes the already SHA256 hashed data in Base64 format and returns the encrypted data in Base64 format. It was designed to allow PowerBuilder do as much of the work as possible, and just do the part that PowerBuilder doesn't currently do. The AsymetricEncrypt function in CrypterObjed does RSA-SHA1, not RSA- SHA256.
The second assembly (RSASigning2) uses Bouncy Castle classes and is dependent on the Bouncy Class assembly included. I couldn't find a way to make Bouncy do just the RSA encryption without also doing the hashing, so it takes the data as a raw string and does both the SHA256 hashing and the RSA encryption.
This message has an attachment file.
Please log in or register to see it.
Last Edit: 9 months 3 weeks ago by Bruce Armstrong. Reason: Updated sample with and additional assembly
Please Log in or Create an account to join the conversation.
Moderators: Appeon Administrator