MarshallSoft

Xbase++ Advanced Encryption Standard (AES) Example


Procedure Main()
LOCAL nVersion
LOCAL nBuild
LOCAL nCode
LOCAL Vector
LOCAL A, B, C
LOCAL Control
LOCAL PassPhrase
LOCAL KeyBuffer
LOCAL SourceFile
LOCAL TargetFile
PassPhrase = "My secret pass phrase"
SourceFile = "\aes4xb\apps\alpha.txt"
Control = "*"
* display pass phrase
? "PassPhrase = '" + PassPhrase + "'"
* make a 256-bit (32-byte) key from user text 'PassPhrase'
PassPhrase = PassPhrase + Chr(0)
KeyBuffer = Space(AES_KEY_SIZE)
nCode = XaesMakeUserKey(@PassPhrase, @KeyBuffer, 0)
* initialization vector not used in ECB mode
Vector = Chr(0)
* initialize AES for encrypting (ECB mode)
nCode = XaesInitAES(@KeyBuffer, @Vector, AES_ECB_MODE, AES_ENCRYPT, @Control)
If nCode < 0
  return nCode
  exit
endif
* display filenames
? "Source file = '" + SourceFile + "'"
? "Target file = '" + TargetFile + "'"
* append null to strings passed to AES functions
SourceFile = SourceFile + Chr(0)
TargetFile = TargetFile + Chr(0)
* encrypt the file
nCode = XaesEncryptFile(@Control, @SourceFile, @TargetFile)
* all done
? "Encryption completed"
return

MSC Logo

HOME PAGE
MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.