Sample code for 30+ languages & platforms
Tcl

Generate Brainpool EC Keys (BP256R1, BP384R1, BP512R1, ...)

See more ECC Examples

Demonstrates how to generate brainpool EC keys.

The brainpool elliptic curve (EC) is a set of standardized elliptic curves defined for use in cryptographic applications. These curves are defined over finite fields and are widely used for implementing elliptic curve cryptography (ECC) algorithms.

The brainpool curves were developed by the brainpool project, a collaborative effort initiated by the German Federal Office for Information Security (BSI) to define standardized elliptic curves with well-established security properties.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

# Create a Fortuna PRNG and seed it with system entropy.
# This will be our source of random data for generating the brainpool EC private key.
set fortuna [new_CkPrng]

set entropy [CkPrng_getEntropy $fortuna 32 "base64"]
set success [CkPrng_AddEntropy $fortuna $entropy "base64"]

set ecc [new_CkEcc]

# You can generate keys using any of the following brainpool EC curves:
# (case does not matter)  
# BP160R1
# BP192R1
# BP224R1
# BP256R1
# BP320R1
# BP384R1
# BP512R1

set privKey [new_CkPrivateKey]

set success [CkEcc_GenKey $ecc "bp256r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

# Save the private key to PKCS8 encrypted PEM
# (The private key can be saved in a variety of different formats. See the online reference documentation.)
set success [CkPrivateKey_SavePkcs8EncryptedPemFile $privKey "pemPassword" "c:/temp/qa_output/eccKey123.pem"]
if {$success != 1} then {
    puts [CkPrivateKey_lastErrorText $privKey]
}

set success [CkEcc_GenKey $ecc "bp160r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

set success [CkEcc_GenKey $ecc "bp192r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

set success [CkEcc_GenKey $ecc "bp224r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

set success [CkEcc_GenKey $ecc "bp320r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

set success [CkEcc_GenKey $ecc "bp384r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

set success [CkEcc_GenKey $ecc "bp512r1" $fortuna $privKey]
if {$success == 0} then {
    puts [CkEcc_lastErrorText $ecc]
    delete_CkPrng $fortuna
    delete_CkEcc $ecc
    delete_CkPrivateKey $privKey
    exit
}

puts [CkPrivateKey_getXml $privKey]

puts "Finished generating Brainpool EC keys."

delete_CkPrng $fortuna
delete_CkEcc $ecc
delete_CkPrivateKey $privKey