If have the follwoing situation:
- A Client app runs on Raspian with .NETCore 2.1 (Linux)
- It encrypts a message with a public cert (RSA)
- Sends this encrypted message to a windows server
- This server decrypts the message
- Now the data has 2 more bytes at the beginning of the text!
Example: Encrypting "Hallo welt" under linux leads to "\u0004\nHallo welt" in windows.
For me it seems that there is a bug in the linux implementation of the .NETCore encryption, or (maybe padding-problem)?
Encryption is done with
public static byte[] Encrypt(byte[] plainData, X509Certificate2 certificate) {
var message = new EnvelopedCms(new ContentInfo(plainData));
message.Encrypt(new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, certificate));
return message.Encode();
}
Decryptiong with:
public static byte[] Decrypt(byte[] encryptedData, X509Certificate2 certificate) {
var message = new EnvelopedCms();
message.Decode(encryptedData);
message.Decrypt(new X509Certificate2Collection {certificate} );
return message.ContentInfo.Content;
}
I can also provide an very simple example project if needed...