IB Statements/cryptosetkeyinfo

From CometWiki

< IB Statements(Difference between revisions)
Jump to: navigation, search
(New page: = CryptoSetKeyInfo = Result$ = CryptoSetKeyInfo(Algorith$, KeyLength, Key$, IV$))
 
(2 intermediate revisions not shown)
Line 1: Line 1:
= CryptoSetKeyInfo =
= CryptoSetKeyInfo =
-
Result$ = CryptoSetKeyInfo(Algorith$, KeyLength, Key$, IV$)
+
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: [http://en.wikipedia.org/wiki/Triple_DES 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: [http://en.wikipedia.org/wiki/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)
 +
    ErrResult$ = CryptoSetKeyInfo("", 0, "", "")
 +
    Wait
 +
Endif
 +
 +
Stop

Latest revision as of 01:04, 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)
   ErrResult$ = CryptoSetKeyInfo("", 0, "", "")
   Wait
Endif

Stop
Personal tools