I am working on a project in which API request & responses are sent after PGP encryption and then Base64 encoding. Similarly, after receiving the request, I have to first decode it with base64 & then PGP decryption is performed.
Whenever I use my own function in .Net to decode the request, PGP decryption gives error of illegal characters or unknown message format. But when I decode the request from an online tool that is https://www.base64decode.org , my PGP decryptor works fine.
I am using DidiSoft.PGP library for PGP encryption/decryption. Below is the code snippet I am using for Base64 decoding:
public static string Base64Decode(string base64EncodedData)
{
//Base64 URL Decode
string converted = base64EncodedData
.Replace('-', '+')
.Replace('_', '/')
.Replace(@"\/", "/");
byte[] base64EncodedBytes = Convert.FromBase64String(converted);
return Encoding.UTF8.GetString(base64EncodedBytes);
}
I wonder what algorithm is used in the online tool, or what I am missing to get the correct string. Any help is appreciated.
EDIT: One additional info I found out that I need to perform Base64 decoding according to RFC4648 Section 5 (RFC 4648 §5: base64url (URL- and filename-safe standard)). Can anyone pls. guide its implementation in .NetCore or is there any NugetPackage to do so