<commit_before>pyjks
=====

A pure python Java KeyStore file parser, including private/secret key decryption. Can read both JKS and JCEKS key stores.

The best way to utilize a certificate stored in a jks file up to this point has been
to use the java keytool command to transform to pkcs12, and then openssl to transform to pem.

This is better:
 -  no security concerns in passwords going into command line arguments, or unencrypted files being left around
 -  no dependency on a JVM

## Requirements:

 * Python 2.6+ (no Python 3 support yet)
 * pyasn1 0.1.7+
 * javaobj-py3 0.1.4+
 * pycrypto, if you need to read JCEKS keystores

## Usage examples:

Reading a JKS or JCEKS keystore and dumping out its contents in the PEM format:
```
import sys, base64, textwrap
import jks

def print_pem(der_bytes, type):
    print "-----BEGIN %s-----" % type
    print "\r\n".join(textwrap.wrap(base64.b64encode(der_bytes).decode('ascii'), 64))
    print "-----END %s-----" % type

ks = jks.KeyStore.load("keystore.jks", "XXXXXXXX")

for pk in ks.private_keys:
    print "Private key: %s" % pk.alias
    if pk.algorithm_oid == jks.RSA_ENCRYPTION_OID:
        print_pem(pk.pkey, "RSA PRIVATE KEY")
    else:
        print_pem(pk.pkey_pkcs8, "PRIVATE KEY")<commit_msg>README.md: Enable Python syntax highlighting on PEM dump usage example<commit_after>pyjks
=====

A pure python Java KeyStore file parser, including private/secret key decryption. Can read both JKS and JCEKS key stores.

The best way to utilize a certificate stored in a jks file up to this point has been
to use the java keytool command to transform to pkcs12, and then openssl to transform to pem.

This is better:
 -  no security concerns in passwords going into command line arguments, or unencrypted files being left around
 -  no dependency on a JVM

## Requirements:

 * Python 2.6+ (no Python 3 support yet)
 * pyasn1 0.1.7+
 * javaobj-py3 0.1.4+
 * pycrypto, if you need to read JCEKS keystores

## Usage examples:

Reading a JKS or JCEKS keystore and dumping out its contents in the PEM format:
```python
import sys, base64, textwrap
import jks

def print_pem(der_bytes, type):
    print "-----BEGIN %s-----" % type
    print "\r\n".join(textwrap.wrap(base64.b64encode(der_bytes).decode('ascii'), 64))
    print "-----END %s-----" % type

ks = jks.KeyStore.load("keystore.jks", "XXXXXXXX")

for pk in ks.private_keys:
    print "Private key: %s" % pk.alias
    if pk.algorithm_oid == jks.RSA_ENCRYPTION_OID:
        print_pem(pk.pkey, "RSA PRIVATE KEY")
    else:
        print_pem(pk.pkey_pkcs8, "PRIVATE KEY")
{'fraction_non_alphanumeric': 0.10477299185098952, 'fraction_numerical': 0.017074117190531625, 'mean_word_length': 3.54673721340388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7331264', 'n_tokens_mistral': 907, 'n_tokens_neox': 849, 'n_words': 327}