I'm trying to figure out the message from a PgP public key, ie so I know with what I private key can decrypt the message.
-----BEGIN PGP MESSAGE-----
Version: BCPG C# v1.7.4114.6375
....
-----END PGP MESSAGE-----
But I found the solutions were for the Java version. See: http://heli0s.darktech.org/?p=433
The C# version don't have "PGPPublicKeyRingCollection". Maybe someone has a tip for me? Or is the only way to work with try and catch?
Dany
Related
I need to decode the encryptedToken with private key file .p12..
For private key, I already assign in X509Certificate2 and calling with
RSA privateKey = _x509private.GetRSAPrivateKey();
I am not using
RSACryptoServiceProvider privateKey = _x509private.PublicKey.Key as RSACryptoServiceProvider;
because that function is already deprecated.
But when I want to use this function to decode the encryptedToken
string plainToken = Jose.JWT.Decode(encryptedToken, privateKey);
What I expected as output is token that I will verify token with public key. But, Unfortunately I get the error message of
Algorithm 'AesGcm' is not supported on this platform.
I was thinking the error message was arise because I didn't use RSACryptoServiceProvider as Private key.
I already search how to convert RSA to RSACryptoServiceProvider, but can't find anything...
I also considering not using the Jose.JWT.Decode(), but no luck...
Is there anyone that can help me?
PS: I am using .NET6 and Visual Studio Mac 2019 V.8
As bartonjs said in this comment, it only affects macOS.
.NET on macOS can’t use Apple’s AES-GCM implementation and requires OpenSSL to be installed to provide the algorithm. How to use .Net Core with Openssl3 on Mac OS? may help.
I'm porting WP8.1 Silverlight to UWP. My WP8.1 Code:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
var key = Resources.key;
rsa.FromXmlString(key);
I used the provider to load the key from xml and to en-/decode.
In UWP this class is not available. So how exactly does it work now? I tried with RSA class and CryptographicEngine, but i cant get it working. How to load my xml key there?
Thanks!
Have read this article RSA cryptography between a WinRT and a .Net app
For each platform, you have the creation of the key pair, the encryption and the description method.
I just got my hands on Cryptography the first time. I have a few questions, espacially about sharing a public Key between two programs:
I have two different applications.
One is coded in C++ and running on a Linux Ubuntu Server. The other one is coded in C# and running on my local Windwos 7 Home-PC.
The two applications connect over TCP and I want to create a secure connection between them. I decided to use the RSA-Algorithm.
I created a Key-Pair on the Serverside and hard-coded them into the C++ application. The Public-Key of the server is also hardcoded into the C# application. Now, when the C# Application (Client) connects to the C++ application (Server), it should generate a personal Key-Pair and send the Public-Key to the server. From here on both sides can encrypt their data and send it to each other.
My problem is that I can't bring the Public-Keys to the "same layout". On the serverside I have to use the OpenSSL-Library since C++ does not come with a inbuilt RSA-Library. So the Key-Pair looks like this (example):
$ openssl genrsa -out private_key.pem 2048
$ openssl rsa -pubout -in private_key.pem -out public_key.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA0DTV2eG8BrhPVWgrqR1PhI5BwLCsuAiBCCDmSShaOsh1uKFW
j7lgBGWyGT77X55DAgXwvjNg+odDfili71poeH/f5/1kCTTC6FFoV6inY0nAcOZ3
...
...
...
...
mxTUFS1Q+vPsmoPCN+C5bP+zv415usUg1Mx8sSly5IS0IQzp2kR8EekhqKLQb06p
2qZfVCuGEXzT+NoT10SOGtZ2+izb+EZM/yRkJFUQS2YwpwPmcZGbAUg=
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0DTV2eG8BrhPVWgrqR1P
...
...
...
eH/f5/1kCTTC6FFoV6inY0nAcOZ3Ang1/fywxz5GVm430GuAqloZqNo/iwMZtHcU
aQIDAQAB
-----END PUBLIC KEY-----
And when I create a Key-Pair in C#, it is in XML-Format:
<RSAKeyValue>
<Modulus>w0tU2IBTdZkLB3G9sze92KR67hM3qdbnYCujrp/GflJ/EMgP1dQxTuHOueq+3DzZnUZDVtYic2QDAdJDVDqRiIFbff7+l5IE24kcgIJSN6vJdnSVAVbSzfyZkftsd4faYx055ZYSH3N4Ev52QepgXVKz7G3S+n2xslzFs09SDOVKiUvmXQEG4CsRef4uB1Kk2ElrZBBpuU3G/V4gNpGkQ/TuPbizQL/Oao3HNhxnCsqxzOOCmNoPSiCesWSWpoPTJrBm2jfX5nDJi+l5u3dYrRLpT8h844Y2yplCeDe4M3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Y7a/cSNdQ2GdMkdIA0K8hbmltuokjBPPXPZW7PEHMZQ7HXiCoyaD8fWXP4lB8YG0viCD5U6C8aPGqnr9jquQgf9EwXxEZvdktOWLO5PJvd4XaQRk47UcNBkjWnwxO1vq28/OSWTNaoEQqpLNwimHEFHl3MN2IuME1zV4MvKyGsKsKO9EytLk/RD28UDFZGlxU6uNAEjOjQp++CgbFRCEHNOCas5kTa1/fuxVg8RdnFeowAq2otWwhwGlwGiJjjmoAQ==</D>
</RSAKeyValue>
Finally, my questions:
Is "----- BEGIN RSA PRIVATE KEY -----" etc. actually a part of the Key? I'm pretty sure it's not, but I'm better making sure. The confusing thing is that when I leave this text in the key and encrypt/decrypt on the C++ application, it works (with OpenSSL lib).
How can I bring the keys to the same structure so I can send them from one application to another and parse them correctly?
Thank you very much for your help!
Summary: how can I generate key.pem file used for packaging google extension using c#?
As far as I know the pem file used in Google extension generated by using below code
openssl pkcs8 -topk8 -nocrypt -out key.pem
and it's pkcs8 key , I tried to use bouncycastle to generate it from RSA XML file like discriped in this post , but the final generated .pem file dose not accepted by google chrome, it's structure is correct but length of the file is almost half of the one generated by chrome browser in the packaging proccess.
the final key required by google chrome is something like below
-----BEGIN PRIVATE KEY-----
MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQC0Bo/mh3bSiOiP
CUxtpa0c8IhDNJqaRDNWaKiqothEjgI7D/IU/uHacPotyedjzLFNr0cnhgguO4dQ
dNaSN+tAlgBqcexBbAl31+BEghNy+1PB189VNVSf8G+qOfF0SIKuBbb/+Q4TrvOD
XPrzulQpLcHMqRGqRE4PkT6574pKyiQGJvjeLBLEQtiobKkzoG3HOFkl9RsKae1f
Tuf8f25aVhKjoUyWp1mOfhHwdfT+76rmrz7F9X1s6M7pxigIfCiYPXHrWh02GTbj
EVLKTpVBg31JmrKErNJsv/j5P3wuSI12TCW4u1RXfahBHhi263oGCQ/2JO/Fm4+v
5wtX20x5AgMBAAECggEBAJjceZPlsp9SYSY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3LzBl+I6Ke9t/TOqCZhwtuolMDkFLhZ9woGDeB1VBfV7yUW4
xyF3rE6uMSEZyD5ivku7VC2Gsz/2XuRGl8iToGXgGxzzg6HMQr6Hw36+0VFzzxSo
xn9/6PuHd1bNooOv1S3s0WVkTJw=
-----END PRIVATE KEY-----
I am attempting to use X509Certificate2 and RSACryptoServiceProvider together with PHP OpenSSL commands to implement two-way mutual security.
It all seems to be fine sending a message from PHP to C#, RSACryptoServiceProvider on the .NET server can decrypt the message using it's own private key and verify the signature using the PHP server's public key.
But going the other way, .NET to PHP, is causing trouble using 'openssl_public_decrypt' to verify the signature of the .NET server. It just returns false. 'openssl_private_decrypt' works fine to decrypt the encrypted data with the PHP server's private key.
I created the RSA (2048)self-signed certificates for both servers using openssl (.key and .crt) and then created a .pfx to use as private key in .NET code.
I am wondering what is the problem here. I am using the default settings for the encryption/decryption on both the .NET and PHP servers. Are the encryption/decryption mechanisms not the same on the case when you have encrypted something with a .pfx? Or does openssl_public_decrypt expect a different encryption from what RSACryptoServiceProvider gives you?
Any help would be great, as I'm not really sure where the issue lies.
openssl_public_decrypt is pretty anal about the format of the public key and doesn't support as many padding schemes as openssl_private_decrypt does.
My recommendation: Use phpseclib, a pure PHP RSA implementation. An example:
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey('...'); // public key
$plaintext = '...';
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($plaintext);
$rsa->loadKey('...'); // private key
echo $rsa->decrypt($ciphertext);
?>
It supports a ton more key formats than OpenSSL does, from XML Signature formatted keys, to PuTTY keys, etc.