티클러 2025. 4. 17. 10:04

홈페이지 : http://www.digitalsmarties.com/cryptkit/

 

Cryptkit은 Cryptlib의 C API와 거의 일치하는 Tcl API를 제공합니다. 현재는 Tcl 스크립트에 C 코드를 포함할 수 있는 Tcl 확장 프로그램인 Critcl을 사용하여 구현되었습니다.

proc testBlobs {} {
    # Demonstrate cryptQueryCapability()
    cryptQueryCapability CRYPT_ALGO_AES q
    puts "AES capabilities:"
    puts "algoName = $q(algoName)"
    puts "blockSize = $q(blockSize)"
    puts "minKeySize = $q(minKeySize)"
    puts "keySize = $q(keySize)"
    puts "maxKeySize = $q(maxKeySize)"

    # Hash some data
    cryptCreateContext hashContext CRYPT_UNUSED CRYPT_ALGO_SHA
    cryptEncrypt $hashContext "hello I am data to hash"
    cryptEncrypt $hashContext ""

    # Generate DSA key
    cryptCreateContext dsaContext CRYPT_UNUSED CRYPT_ALGO_DSA
    cryptSetAttributeString $dsaContext CRYPT_CTXINFO_LABEL "testkey"
    cryptGenerateKey $dsaContext

    # Produce a signature
    set buffer [binary format a1000 \0]
    cryptCreateSignature buffer siglength $dsaContext $hashContext 

    # Query the signature blob
    cryptQueryObject $buffer i
    puts "Signature Properties: "
    puts "objectType = $i(objectType)"
    puts "cryptAlgo = $i(cryptAlgo)"
    puts "cryptMode = $i(cryptMode)"
    puts "hashAlgo = $i(hashAlgo)"
    puts "salt = $i(salt)"

    # Validate the signature
    cryptCheckSignature $buffer $dsaContext $hashContext
    puts "The signature validates correctly!"

    # Generate a symmetric key
    cryptCreateContext aesContext CRYPT_UNUSED CRYPT_ALGO_AES
    cryptGenerateKey $aesContext

    # Generate a symmetric key to wrap the first one
    cryptCreateContext desContext CRYPT_UNUSED CRYPT_ALGO_3DES
    cryptSetAttributeString $desContext CRYPT_CTXINFO_KEYING_SALT \
                        "this is salt sdfsdf"
    cryptSetAttributeString $desContext CRYPT_CTXINFO_KEYING_VALUE \
                        "secret password"

    # Wrap the first key in the second
    cryptExportKey buffer exportedKeyLength $desContext $aesContext

    # Query the encrypted key
    cryptQueryObject $buffer i
    puts "Exported Key Properties: "
    puts "objectType = $i(objectType)"
    puts "cryptAlgo = $i(cryptAlgo)"
    puts "cryptMode = $i(cryptMode)"
    puts "hashAlgo = $i(hashAlgo)"
    puts "salt = $i(salt)"

    cryptDestroyContext $dsaContext
    cryptDestroyContext $hashContext
    cryptDestroyContext $aesContext
    cryptDestroyContext $desContext
}

cryptkit.tar.gz
0.03MB