Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can anyone help with vfpencryption71.fll?
Message
From
02/03/2013 08:17:21
 
 
To
02/03/2013 07:22:51
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
01567286
Message ID:
01567301
Views:
143
This message has been marked as the solution to the initial question of the thread.
>>>I've read the documentation that states the format is:
>>>
>>>
>>>
>>>Encrypt(cStringtoEncrypt, cSecretKey[, nEncryptionType[, nEncryptionMode[, nPaddingType[, nKeySize[, nBlockSize[, cIV]]]]]])
>>>Decrypt(cEncryptString, cSecretKey[, nDecryptionType[, nDecryptionMode[, nPaddingType[, nKeySize[, nBlockSize[, cIV]]]]]])
>>>
>>>
>>>But I need real values to be able to understand this.
>>>
>>>Thanks to anyone who can help!
>>>
>>>dg
>>
>>http://www.sweetpotatosoftware.com/spsblog/2009/08/09/MajorVFPEncryptionUpdate.aspx
>
>
>Yep, that's the documentation I got. I need the actual code, eg.
>
>
>
>Encrypt('915-555-1212', 'MyKey'[, 6[, 'yadda'[,32[, 8[, 64[, SomeValue]]]]]])
>
>
>
>I'm at a loss to know what values to use as the parameters.
>
>Thanks,
>
>dg

For block ciphers, it may help to read this first http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation


cStringtoEncrypt -not difficult
cSecretKey - depends on nEncryptionType. Length 16 for nEncryptionType = 0, 24 for nEncryptionType = 1, 32 for nEncryptionType = 2

nEncryptionType : use any of 0, 1, or 2

nEncryptionMode: use 0 ECB or 1 CBC.
CBC is better when the length of the cStringtoEncrypt >= blockSize

nPaddingMode - see http://en.wikipedia.org/wiki/Padding_(cryptography)
I prefer ISO10126. Don't use zero padding

nKeySize : should match the length of cSecretKey

nBlockSize : use 16, 24 or 32 for nEncryptionType 0, 1, or 2
AES encryption can only handle block sizes of 16, where Rijndael handles 16, 24 or 32


cIV : don't need it for nEncryptionMode = ECB
otherwise, for CBC the length has to equal to nBlockSize


Bear in mind that for block ciphers - the encrypted block will be longer than the original block due to padding. The length of the encrypted block will be a multiple of the blocksize


Example - I'll stick to AES (block size is 16 bytes)


Hope following example helps
function EncryptionTest()

	set library to D:\tmp\In\vfpencryption90\vfpencryption.fll additive
	
	local	cStringtoEncrypt, ;
			cSecretKey, ;
			nEncryptionType, ;
			nKeySize, ;
			nEncryptionMode, ;
			nPaddingType, ;
			nBlockSize, ;
			cIV
		
	&& Encrypt
	cStringtoEncrypt = '915-555-1212'
	nEncryptionType = 2 && or 0 or 1
	
	do case
	case m.nEncryptionType == 0
		nKeySize = 16
	
	case m.nEncryptionType == 1
		nKeySize = 24
	
	case m.nEncryptionType == 2
		nKeySize = 32
	
	otherwise
		error 'unknown nEncryptionType '
	
	endcase
	
	cSecretKey = padr('MyKey', m.nKeySize, chr(0))
	
	nEncryptionMode = 1 && CBC - we will need an IV
	
	nPaddingType = 4 && ISO 10126

	nBlockSize = 16 && or 24 or 32
	
	cIV = replicate(chr(0), m.nBlockSize) && Can be anything - but nBlockSize long
	
	local encryptedValue
	
	encryptedValue = ENCRYPT(m.cStringtoEncrypt, m.cSecretKey, m.nEncryptionType, m.nEncryptionMode, m.nPaddingType, m.nKeySize, m.nBlockSize, m.cIv)
	
	? len(m.encryptedValue), strconv(m.encryptedValue,15)
	
	
	local decryptedValue
	
	decryptedValue= Decrypt(m.encryptedValue, m.cSecretKey, m.nEncryptionType, m.nEncryptionMode, m.nPaddingType, m.nKeySize, m.nBlockSize, m.cIv)
	
	? len(m.decryptedValue), m.decryptedValue, '  ', m.decryptedValue == cStringtoEncrypt 
	
	
	

*_______________________________________________________________________________
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform