Revision history for ExtLibcryptlib


Revision [22549]

Last edited on 2019-01-13 18:50:51 by JeffMarshall [example updated from repo]
Additions:
Dim As Long buffersize = BUFFER_SIZE
Deletions:
Dim As Integer buffersize = BUFFER_SIZE


Revision [22472]

Edited on 2018-09-03 16:39:40 by JeffMarshall [small fix to compile example]
Additions:
#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 )
Dim As CRYPT_CONTEXT ctx
Dim As Integer f = FreeFile()
If( Open( filename For Binary Access Read As #f ) <> 0 ) Then
Return ""
End If
Do Until( EOF( f ) )
Dim As Integer oldpos = Seek( f )
Get #f, , buffer()
Dim As Integer readlength = Seek( f ) - oldpos
Loop
Close #f
Dim As Integer buffersize = BUFFER_SIZE
Dim As String result = ""
For i As Integer = 0 To buffersize-1
result += Hex( buffer(i) )
Next
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
Print "md5: "; calc_hash( filename, CRYPT_ALGO_MD5 )
Print "sha1: "; calc_hash( filename, CRYPT_ALGO_SHA1 )
Sleep
Deletions:
#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 )
dim as CRYPT_CONTEXT ctx
dim as integer f = freefile()
if( open( filename for binary access read as #f ) <> 0 ) then
return ""
end if
do until( eof( f ) )
dim as integer oldpos = seek( f )
get #f, , buffer()
dim as integer readlength = seek( f ) - oldpos
loop
close #f
dim as integer buffersize = BUFFER_SIZE
dim as string result = ""
for i as integer = 0 to buffersize-1
result += hex( buffer(i) )
next
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
print "md5: "; calc_hash( filename, CRYPT_ALGO_MD5 )
print "sha: "; calc_hash( filename, CRYPT_ALGO_SHA )
sleep


Revision [16786]

Edited on 2013-05-01 12:49:02 by DkLwikki [Update examples path]
Additions:
Examples: in examples/math/cryptlib/


Revision [16314]

Edited on 2012-08-21 11:08:21 by DkLwikki [Fix example]
Additions:
for i as integer = 0 to buffersize-1
Deletions:
for i as integer = 0 to length-1


Revision [15929]

Edited on 2012-02-02 10:39:07 by DkLwikki [Add version]
Additions:
Header version: from 2005


Revision [15431]

Edited on 2011-10-11 11:19:54 by CountingPine [Remove CamelCase link]
Additions:
Platforms supported: ""Win32"", Linux
Deletions:
Platforms supported: Win32, Linux


Revision [15349]

Edited on 2011-10-05 03:26:29 by DkLwikki [Add example]
Additions:
{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/libraries/cryptlib.bas"}}%%(freebasic)
#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 integer buffersize = BUFFER_SIZE
cryptGetAttributeString( ctx, CRYPT_CTXINFO_HASHVALUE, @buffer(0), @buffersize )
'' convert to hexadecimal
dim as string result = ""
for i as integer = 0 to length-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 "sha: "; calc_hash( filename, CRYPT_ALGO_SHA )
'' shutdown cryptlib
cryptEnd( )
sleep
%%
Deletions:
Example Usage: yes, in examples/libraries/cryptlib/


Revision [10956]

The oldest known version of this page was created on 2007-09-02 05:24:26 by JeffMarshall [Add example]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode