C Generate Rsa Public Private Key Pair Bouncycastle
Chilkat • HOME • Android™ • Classic ASP • C • C++ • C# • Mono C# • .NET Core C# • C# UWP/WinRT • DataFlex • Delphi ActiveX • Delphi DLL • Visual FoxPro • Java • Lianja • MFC • Objective-C • Perl • PHP ActiveX • PHP Extension • PowerBuilder • PowerShell • PureBasic • CkPython • Chilkat2-Python • Ruby • SQL Server • Swift 2 • Swift 3/4 • Tcl • Unicode C • Unicode C++ • Visual Basic 6.0 • VB.NET • VB.NET UWP/WinRT • VBScript • Xojo Plugin • Node.js • Excel • Go
- C# (CSharp) Org.BouncyCastle.Crypto AsymmetricCipherKeyPair - 30 examples found. These are the top rated real world C# (CSharp) examples of Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair extracted from open source projects. You can rate examples to help us improve the quality of examples.
- Oct 23, 2008 Hi all, The other day a colleague of mine asked me if I had a.NET version of the C sample in How to generate key pairs, encrypt and decrypt data with CryptoAPI post. C sample calls CryptoAPI directly (and you know we can do the same thing in.NET through P/Invoke), but the idea was to use System.Security classes in order to get a pure.NET solution.
- Generate a RSA key pair - The bouncy castle type – RSAKeyPairGenerator has been used for generating the asymmetric key pair. The RSAKeyPairGenerator uses two large prime numbers for generating the private and the public keys.
| C++ example code showing how to generate an RSA public/private key.
|
© 2000-2020 Chilkat Software, Inc. All Rights Reserved.
In OpenPGP, 'key rings' are some terminology for 'public and/or private keys encoded in the format described by OpenPGP'. Among the types of keys for which OpenPGP describes a key ring format are RSA keys. There is no fundamental issue which would prevent an OpenPGP implementation from using a RSA private key which is stored in a HSM.
// Here you can find full description: https://thetial.com/rsa-encryption-and-decryption-net-core/ |
using System; |
using System.IO; |
using System.Text; |
using System.Collections.Generic; |
using Org.BouncyCastle.Crypto; |
using Org.BouncyCastle.Crypto.Encodings; |
using Org.BouncyCastle.Crypto.Engines; |
using Org.BouncyCastle.OpenSsl; |
using Org.BouncyCastle.Crypto.Parameters; |
namespace ConsoleApplication |
{ |
class Program |
{ |
static void Main(string[] args) |
{ |
string plainText = @'Connect with me on linkedin: https://www.linkedin.com/in/dziwoki'; |
string cihperText = encrypt(plainText); |
string decryptedCipherText = decrypt(cihperText); |
Console.WriteLine('Encrypted text: {0}', cihperText); |
Console.WriteLine('Decrypted text {0}. Encryption/Decryption was correct {1}', |
decryptedCipherText, (plainText decryptedCipherText).ToString()); |
} |
static string encrypt(string plainText) { |
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); |
PemReader pr = new PemReader( |
(StreamReader)File.OpenText('./pem_public.pem') |
); |
RsaKeyParameters keys = (RsaKeyParameters)pr.ReadObject(); |
// Pure mathematical RSA implementation |
// RsaEngine eng = new RsaEngine(); |
// PKCS1 v1.5 paddings |
// Pkcs1Encoding eng = new Pkcs1Encoding(new RsaEngine()); |
// PKCS1 OAEP paddings |
OaepEncoding eng = new OaepEncoding(new RsaEngine()); |
eng.Init(true, keys); |
int length = plainTextBytes.Length; |
int blockSize = eng.GetInputBlockSize(); |
List<byte> cipherTextBytes = new List<byte>(); |
for (int chunkPosition = 0; |
chunkPosition < length; |
chunkPosition += blockSize) |
{ |
int chunkSize = Math.Min(blockSize, length - chunkPosition); |
cipherTextBytes.AddRange(eng.ProcessBlock( |
plainTextBytes, chunkPosition, chunkSize |
)); |
} |
return Convert.ToBase64String(cipherTextBytes.ToArray()); |
} |
static string decrypt(string cipherText) { |
byte[] cipherTextBytes = Convert.FromBase64String(cipherText); |
PemReader pr = new PemReader( |
(StreamReader)File.OpenText('./pem_private.pem') |
); |
AsymmetricCipherKeyPair keys = (AsymmetricCipherKeyPair)pr.ReadObject(); |
// Pure mathematical RSA implementation |
// RsaEngine eng = new RsaEngine(); |
// PKCS1 v1.5 paddings |
// Pkcs1Encoding eng = new Pkcs1Encoding(new RsaEngine()); |
// PKCS1 OAEP paddings |
OaepEncoding eng = new OaepEncoding(new RsaEngine()); |
eng.Init(false, keys.Private); |
int length = cipherTextBytes.Length; |
int blockSize = eng.GetInputBlockSize(); |
List<byte> plainTextBytes = new List<byte>(); |
for (int chunkPosition = 0; |
chunkPosition < length; |
chunkPosition += blockSize) |
{ |
int chunkSize = Math.Min(blockSize, length - chunkPosition); |
plainTextBytes.AddRange(eng.ProcessBlock( |
cipherTextBytes, chunkPosition, chunkSize |
)); |
} |
return Encoding.UTF8.GetString(plainTextBytes.ToArray()); |
} |
} |
} |
commented Jan 29, 2017
Here you can find full description: RSA encryption and decryption with PEM keys in C# |
commented Oct 31, 2018
This is great stuff! Thanks |
commented Mar 28, 2019
If client side uses the above code for RSA Encryption, a math very similar to the one which is written above would be required for RSA Decryption right ? Or some .NET framework classes like RSACryptoServiceProvider can Decrypt as well ? |
commented Jun 18, 2019
How to download html5 video mac. Exactly what I've been trying to achieve. Thanks for posting this. |