Import a Public key from somewhere else to CngKey?

So I have figured out the format of a CngKey exported in ECCPublicKeyBlob and ECCPrivateKeyBlob. This should allow others to interop between other key formats and CngKey for Elliptcal Curve signing and such. ECCPrivateKeyBlob is formatted (for P256) as follows [KEY TYPE (4 bytes)][KEY LENGTH (4 bytes)][PUBLIC KEY (64 bytes)][PRIVATE KEY (32 Bytes)] KEY TYPE … Read more

Generate Subject Hash of X509Certificate in Java

This generates a short 8 digit hash 1817886a There are two forms of this from OpenSSL: $ cd openssl-1.0.2-src $ grep -R X509_subject_name_hash * … crypto/x509/x509.h:unsigned long X509_subject_name_hash(X509 *x); crypto/x509/x509.h:unsigned long X509_subject_name_hash_old(X509 *x); crypto/x509/x509_cmp.c:unsigned long X509_subject_name_hash(X509 *x) crypto/x509/x509_cmp.c:unsigned long X509_subject_name_hash_old(X509 *x) … Generate Subject Hash of X509Certificate in Java… Here is the source for them … Read more

TLS 1.2 + Java 1.6 + BouncyCastle

If you look at RFC 4492 5.2, you’ll see that the server CAN send the “ec_point_formats” extension, but is only supposed to do so “when negotiating an ECC cipher suite”. If you want TLSClient to just ignore the extra extension instead of raising an exception, I suggest overriding TlsClient.allowUnexpectedServerExtension(…) to allow ec_point_formats in the same … Read more

How to add Bouncy Castle algorithm to Android?

None of these answers is accurate in 2021 or even several years prior. Neither using Spongy Castle nor recompiling Bouncy Castle with a different package namespace are necessary since the package name conflicts on Android platform were resolved in Honeycomb (unless you still support pre-honeycomb devices). For details why see: https://github.com/rtyley/spongycastle/issues/34 The correct solution is … Read more

iText/BouncyCastle ClassNotFound org.bouncycastle.asn1.DEREncodable and org.bouncycastle.tsp.TimeStampTokenInfo

iText marks bouncycastle dependencies as optional. If you require them, you need to add the dependencies in your own pom file. To find out which dependency to include in your project, open the itextpdf pom.xml file of the version you are using (for example 5.3.2, here) and search for the 2 bouncycastle dependencies. <dependency> <groupId>org.bouncycastle</groupId> … Read more

Wrong version of keystore on android call

You need to change the type of the keystore, from BKS to BKS-v1 (BKS-v1 is an older version of BKS). Because the BKS version changed as said here There is another solution, that is much much easier: Using Portecle: Downloads Portecle http://portecle.sourceforge.net/ Open your bks file with the password and portecle Do Tools>>Change Keystore Type>>BKS-v1 … Read more

Bouncy Castle : PEMReader => PEMParser

I just needed to solve the same problem and found no answer. So I spent some time studying BC API and found a solution which works for me. I needed to read the private key from file so there is privateKeyFileName parameter instead pemString parameter in the myFunc method. Using BC 1.48 and PEMParser: int … Read more