bouncycastle

Convert .crt + .key files to X509Certificate2 programmatically in C#

﹥>﹥吖頭↗ 提交于 2020-01-05 04:37:16
问题 I have a .crt certificate and a .key private key file on a Linux machine. The private key is in encrypted PKCS#8 format (BEGIN ENCRYPTED PRIVATE KEY...). I would like to import these into an X509Certificate2 object for further use. Since we're on Linux, we're using .NET Core 2.2 (we cannot migrate to 3.0 yet). I have explored a few possible solutions, detailed below: Use openssl to convert the files to a .pfx and import that using X509Certificate2 I do not want to use this option since I don

convert PEM encoded RSA private key to AsymmetricKeyParameter

╄→гoц情女王★ 提交于 2020-01-05 02:46:12
问题 I am trying (but failing) to create a method that constructs an AsymmetricKeyParameter from a PEM encoded private key. How can I complete this method? It seems that an older version of BouncyCastle had a pemReader.ReadObject() method whose results could be casted, but that no longer exists. I have tried various combinations of using PrivateKeyFactory , PrivateKeyInfo , Asn1Object and perhaps 10 other types, but all are throwing an exception at some point. static AsymmetricKeyParameter

How to use BouncyCastle lightwigth API to generate cms enveloped data

柔情痞子 提交于 2020-01-03 05:16:11
问题 After struggling uncountable hours I finally have the current working code to generate CMS enveloped (RSA-OAEP / PKCS#1) data with recipient info using JCE/JCA: String digest = "SHA-256"; String mgfDigest = "SHA-256"; // Data to encrypt CMSTypedData msg = new CMSProcessableByteArray(data); // Generator for my CMS enveloped data CMSEnvelopedDataGenerator envelopedDataGen = new CMSEnvelopedDataGenerator(); // Recipient Info Stuff JcaAlgorithmParametersConverter paramsConverter = new

Use BouncyCastle PKCS12SafeBagBuilder or PKCS12BagAttributeCarrier to change PKCS12 safe bag attributes when writing KeyStore to file in Android?

♀尐吖头ヾ 提交于 2020-01-03 03:42:27
问题 I am trying to write a private key and associated signed certificate to a PKCS12 (.p12) file on an Android device using BouncyCastle 1.47 ( bckpix-jdk15on-147.jar and bcprov-jdk15on-147.jar ) and would like to change the key encryption algorithms and other bag attributes. I am trying to implement the same control available to OpenSSL's PKCS12_create() function, where you can set: the private key encryption algorithm the certificate encryption algorithm the encryption iteration count the MAC

convert Bouncy Castle's AsymmetricCipherKeyPair (RSA) to java.security.KeyPair

笑着哭i 提交于 2020-01-03 00:54:11
问题 I am trying to automate generation of CA and certificates for our E2E testing. I started with Bouncy Castle and I have managed to generate CA cert and machine cert. However, now I need to convert the RSA keypair represented by BC' org.bouncycastle.crypto.AsymmetricCipherKeyPair to java.security.KeyPair . I cannot seem to find a way to do this. 回答1: There's probably more than one way to do it, but here is one example: import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org

Using BouncyCastle for a simple HTTPS query

折月煮酒 提交于 2020-01-02 18:56:07
问题 Here's a simplified version of the code I'm using to perform simple HTTPS requests: // Assume the variables host, file and postData have valid String values final URL url = new URL("https", host, file); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestProperty("Content-length", String.valueOf(postData.length())); final DataOutputStream output = new

C# PCL HMACSHAX with BouncyCastle-PCL

早过忘川 提交于 2020-01-02 18:07:34
问题 I want to implement this logic in portable C# class: static JsonWebToken() { HashAlgorithms = new Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>> { { JwtHashAlgorithm.HS256, (key, value) => { using (var sha = new HMACSHA256(key)) { return sha.ComputeHash(value); } } }, { JwtHashAlgorithm.HS384, (key, value) => { using (var sha = new HMACSHA384(key)) { return sha.ComputeHash(value); } } }, { JwtHashAlgorithm.HS512, (key, value) => { using (var sha = new HMACSHA512(key)) { return sha

C# PCL HMACSHAX with BouncyCastle-PCL

佐手、 提交于 2020-01-02 18:05:00
问题 I want to implement this logic in portable C# class: static JsonWebToken() { HashAlgorithms = new Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>> { { JwtHashAlgorithm.HS256, (key, value) => { using (var sha = new HMACSHA256(key)) { return sha.ComputeHash(value); } } }, { JwtHashAlgorithm.HS384, (key, value) => { using (var sha = new HMACSHA384(key)) { return sha.ComputeHash(value); } } }, { JwtHashAlgorithm.HS512, (key, value) => { using (var sha = new HMACSHA512(key)) { return sha

Java ECC encoded Key too large

喜你入骨 提交于 2020-01-02 16:14:12
问题 I am new to the EC-encryption and have some struggle with it. I am using Java 8 and the BouncyCatle provider. The Question I have now is: when I generate an EC-KeyPair with the folloing code: ECGenParameterSpec spec = new ECGenParameterSpec("secp521r1"); KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME); kpg.initialize(spec, new SecureRandom()); return kpg.generateKeyPair(); and try to get the byte array of the public key to send it to another

Bouncy Castle i cannot get all certificate

孤人 提交于 2020-01-02 15:14:10
问题 I'm trying to read certificate from smime.p7s file, the certificate chain is: Baltimora Cyber Trust --> DigitPA --> Aruba PEC So when i'm trying to extract, I retrieve only the last two certificate, the last like subject and the first like issuer. What am I wrong? the code: private List<CertificateInfo> reading(ASN1InputStream asn1Stream) throws IOException, CMSException, CertificateException { ArrayList<CertificateInfo> infos = new ArrayList<CertificateInfo>(); ASN1Primitive obj = asn1Stream