Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
808 B
1
Indexable
Never
import os

def load_private_keys(file):
    with open(file, 'r') as f:
        keys = f.read().split('-----END RSA PRIVATE KEY-----')
        keys = [k + '-----END RSA PRIVATE KEY-----' for k in keys[:-1]]  # reattach the end marker
    return keys

# replace these with your actual file paths
private_keys_file = '/path/to/private_keys.pem'
output_folder = '/path/to/output_folder'

private_keys = load_private_keys(private_keys_file)

# create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)

for i, key in enumerate(private_keys):
    output_file = os.path.join(output_folder, f'private_key_{i}.pem')
    with open(output_file, 'w') as f:
        f.write(key)

print(f'Split {len(private_keys)} private keys into separate files in {output_folder}.')