IB Statements/cryptosetkeyinfo
From CometWiki
Line 23: | Line 23: | ||
'''Example:''' | '''Example:''' | ||
- | Length | + | Set Algorithm$ = "3DES" |
- | Length | + | Set KeySize = 192 ! 3DES(168) requires 192 bits (parity bit is dropped) |
+ | Set BlockSize = 8 ! 3DES block size is always 8 | ||
+ | |||
+ | Length DYNAMIC & Local Key$ | ||
+ | Length DYNAMIC & Local IV$ | ||
Length DYNAMIC & Local ErrResult$ | Length DYNAMIC & Local ErrResult$ | ||
Length DYNAMIC & Local Encr$, Decr$ | Length DYNAMIC & Local Encr$, Decr$ | ||
Line 30: | Line 34: | ||
Print (cs);(et) | Print (cs);(et) | ||
+ | Print "Testing: Algorithm: ";Algorithm$;", Key Size: ";KeySize;", Block Size: ";BlockSize | ||
+ | Print "" | ||
+ | |||
Print "Enter something to encrypt:" | Print "Enter something to encrypt:" | ||
Input Data$ | Input Data$ | ||
If (Data$ NE "") | If (Data$ NE "") | ||
- | Key$ = CryptoGenerateRandom( | + | Key$ = CryptoGenerateRandom(KeySize/8) ! Generate a key |
- | IV$ = CryptoGenerateRandom( | + | IV$ = CryptoGenerateRandom(BlockSize) ! Generate a IV |
! Pass info to crypto sub-system | ! Pass info to crypto sub-system | ||
- | ErrResult$ = CryptoSetKeyInfo( | + | ErrResult$ = CryptoSetKeyInfo(Algorithm$, KeySize, Key$, IV$) |
If (ErrResult$ EQ "+OK") | If (ErrResult$ EQ "+OK") | ||
Encr$ = Encrypt(Data$, "") | Encr$ = Encrypt(Data$, "") |
Revision as of 01:00, 7 June 2010
CryptoSetKeyInfo
Result$ = CryptoSetKeyInfo(Algorithm$, KeyLength, Key$, IV$)
CryptoSetKeyInfo function
Syntax: result-string = CryptoSetKeyInfo(Algorithm$, KeySize, Key$, IV$)
Discussion: The CryptoSetKeyInfo function is used to specify an algorithm and all of the parameters required for use with the Encrypt/Decrypt functions. The result-string will return "+OK" if the function is successful or if a error occurs, "-ERR" followed by a description of the error.
Algorithms: The CryptoSetKeyInfo function currently supports 2 algorithms, 3DES and AES. Each of these algorithms has specific requirements as to the supported Key size and IV (Initial Vector) size as follows:
3DES - Triple Data Encryption Standard: Wiki
- Key Size: 24 bytes (192 bits must be supplied although only 168 bits are used - parity bit is discarded).
- IV Size: 8 Bytes
AES - Advanced Encryption Standard: Wiki
- Key Size: 16, 24, or 32 bytes (128, 192, 256 bits)
- IV Size: 16 Bytes
History: This function is available in Comet32 only.
Example:
Set Algorithm$ = "3DES" Set KeySize = 192 ! 3DES(168) requires 192 bits (parity bit is dropped) Set BlockSize = 8 ! 3DES block size is always 8 Length DYNAMIC & Local Key$ Length DYNAMIC & Local IV$ Length DYNAMIC & Local ErrResult$ Length DYNAMIC & Local Encr$, Decr$ Length DYNAMIC & Local Data$ Print (cs);(et) Print "Testing: Algorithm: ";Algorithm$;", Key Size: ";KeySize;", Block Size: ";BlockSize Print "" Print "Enter something to encrypt:" Input Data$ If (Data$ NE "") Key$ = CryptoGenerateRandom(KeySize/8) ! Generate a key IV$ = CryptoGenerateRandom(BlockSize) ! Generate a IV ! Pass info to crypto sub-system ErrResult$ = CryptoSetKeyInfo(Algorithm$, KeySize, Key$, IV$) If (ErrResult$ EQ "+OK") Encr$ = Encrypt(Data$, "") Decr$ = Decrypt(Encr$, "") Print "Before:";Data$ Print "After:";Decr$ Else Print "CryptoSetKeyInfo failed: ";ErrResult$ EndIf ! For compatibility in other programs, when done reset algorithm back to old default (RC4) CryptoSetKeyInfo("", 0, "", "") Wait Endif Stop