Skip to content

Instantly share code, notes, and snippets.

@gtaban
gtaban / self-signed.swift
Created August 30, 2017 16:00
Handling a self-signed cert
class MyConnection: URLSessionDelegate {
func httpGet(request: URLRequest) {
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: self, delegateQueue:OperationQueue.main)
let task = session.dataTask(with: request){
(data, response, error) -> Void in

The default format of keys was changed in OpenSSL 1.0. From OpenSSL 1.0 change log:

Make PKCS#8 the default write format for private keys, replacing the traditional format. This form is standardised, more secure and doesn't include an implicit MD5 dependency. [Steve Henson]

Good explanations of the difference between the two formats: https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem

Converting RSA private key:

version OpenSSL 1.0.2g

  • Generate an EC key in the named curve form, which unfortunately isn't the default form in all versions of OpenSSL.
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve -outform PEM  -out key.pem

Alternatively, can use openssl ecparam -name secp521r1 -genkey -param_enc explicit -out private-key.pem but not useful for use with the crypto library of other languages. Most libraries expect the named_curve option.

@gtaban
gtaban / ellipticCurve.md
Created August 4, 2017 20:49
Elliptic Curve Crypto
  • Generate an EC key
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve -outform PEM  -out key.pem

Alternatively, can use openssl ecparam -name secp521r1 -genkey -param_enc explicit -out private-key.pem but not useful for use with the crypto library of other languages. Most libraries expect the named_curve option.

According to golang/go#18634: