FreeBASIC マニュアルのトップに戻る

FreeBASIC ExtLibcryptlib

目次→その他→ライブラリ・ヘッダー索引cryptlib←オリジナル・サイト
目次→FreeBASIC のハッキング→FreeBASIC でのハッキングのための情報外部ライブラリ索引cryptlib←オリジナル・サイト

cryptlib


暗号に無経験なプログラマでも、容易にソフトウェアに暗号化と認証サービスを加えることができるようになる、強力なセキュリティ・ツールキット。

ウエブ・サイト: http://www.cs.auckland.ac.nz/~pgut001/cryptlib/
利用できる環境: Win32, Linux
include するヘッダー: cryptlib.bi
ヘッダー・バージョン: from 2005〜
使用例: examples/math/cryptlib/

例:
#include once "cryptlib.bi"

Function calc_hash( ByVal filename As String, ByVal algo As CRYPT_ALGO_TYPE ) As String
    Const BUFFER_SIZE = 8192
    Dim As Byte buffer( 0 To BUFFER_SIZE-1 )

    '' create a new context using the wanted algorithm
    Dim As CRYPT_CONTEXT ctx
    cryptCreateContext( @ctx, CRYPT_UNUSED, algo )

    '' open input file in binary mode
    Dim As Integer f = FreeFile()
    If( Open( filename For Binary Access Read As #f ) <> 0 ) Then
        Return ""
    End If

    '' read until end-of-file
    Do Until( EOF( f ) )
        Dim As Integer oldpos = Seek( f )
        Get #f, , buffer()
        Dim As Integer readlength = Seek( f ) - oldpos
        '' encrypt
        cryptEncrypt( ctx, @buffer(0), readlength )
    Loop

    '' close input file
    Close #f

    '' finalize
    cryptEncrypt( ctx, 0, 0 )

    '' get the hash result
    Dim As Long buffersize = BUFFER_SIZE
    cryptGetAttributeString( ctx, CRYPT_CTXINFO_HASHVALUE, @buffer(0), @buffersize )

    '' convert to hexadecimal
    Dim As String result = ""
    For i As Integer = 0 To buffersize-1
        result += Hex( buffer(i) )
    Next
   
    '' free the context
    cryptDestroyContext( ctx )

    Return result
End Function

    Dim As String filename = Trim( Command(1) )
    If( Len( filename ) = 0 ) Then
        Print "Usage: hash.exe filename"
        End -1
    End If

    '' init cryptlib
    cryptInit( )

    '' calculate hashes
    Print "md5: "; calc_hash( filename, CRYPT_ALGO_MD5 )
    Print "sha1: "; calc_hash( filename, CRYPT_ALGO_SHA1 )

    '' shutdown cryptlib
    cryptEnd( )

    Sleep


外部ライブラリー目次に戻る

ページ歴史:2019-01-13 18:50:51
日本語翻訳:WATANABE Makoto、原文著作者:SirMud

ホームページのトップに戻る

表示-非営利-継承