IB Statements/cryptosetkeyinfo
From CometWiki
|  (New page: = CryptoSetKeyInfo =  Result$ = CryptoSetKeyInfo(Algorith$, KeyLength, Key$, IV$)) | |||
| Line 1: | Line 1: | ||
| = CryptoSetKeyInfo = | = CryptoSetKeyInfo = | ||
| - | Result$ = 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: [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:''' | ||
| + | |||
| + |  Length 24 & Local Key$ | ||
| + |  Length 8 & Local IV$ | ||
| + |  Length DYNAMIC & Local ErrResult$ | ||
| + |  Length DYNAMIC & Local Encr$, Decr$ | ||
| + |  Length DYNAMIC & Local Data$ | ||
| + | |||
| + |  Print (cs);(et) | ||
| + |  Print "Enter something to encrypt:" | ||
| + |  Input Data$ | ||
| + |  If (Data$ NE "") | ||
| + |     Key$ = CryptoGenerateRandom(24)! Generate a key | ||
| + |     IV$ = CryptoGenerateRandom(8)  ! Generate a IV | ||
| + | |||
| + |     ! Pass info to crypto sub-system | ||
| + |     ErrResult$ = CryptoSetKeyInfo("3DES", 192, 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 | ||
Revision as of 00:54, 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:
Length 24 & Local Key$
Length 8 & Local IV$
Length DYNAMIC & Local ErrResult$
Length DYNAMIC & Local Encr$, Decr$
Length DYNAMIC & Local Data$
Print (cs);(et)
Print "Enter something to encrypt:"
Input Data$
If (Data$ NE "")
   Key$ = CryptoGenerateRandom(24)! Generate a key
   IV$ = CryptoGenerateRandom(8)  ! Generate a IV
   ! Pass info to crypto sub-system
   ErrResult$ = CryptoSetKeyInfo("3DES", 192, 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
				
				
	