(no subject)
johanrop
wiki
(Thread)
Last updated: 2023-04-02
wiki Discussion
siwasubramaniam
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03
blog Discussion
siwasubramaniam
blog
(Discussion)
Forum for blog comments
Last updated: 2023-04-03
Home
siwasubramaniam
wiki
(WikiPage)
This is the personal project of siwasubramaniam. This project is created automatically during user registration as an easy place to store personal data that doesn't need its own project such as cloned repositories.
Last updated: 2023-04-03
wiki Discussion
tsaroo
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03
blog Discussion
tsaroo
blog
(Discussion)
Forum for blog comments
Last updated: 2023-04-03
(no subject)
siwasubramaniam
wiki
(Thread)
Last updated: 2023-04-03
Post by siwasubramaniam on #9 Encrypt and Decrypt using AES_128_CFB algorithm
IEC Snippets
snippets
(Post)
Does this work? I tried it and it doesn't give me a value for the sCipherText nor sDecipherText. I've tried the CryptoDemo file too, same problem.
Last updated: 2023-04-03
Ticket #9: Encrypt and Decrypt using AES_128_CFB algorithm
IEC Snippets
snippets
(Ticket)
Based on Crypto Example PROGRAM PLC_PRG VAR Result1, Result2, Result3, Result4 : RTS_IEC_RESULT; _hCipher : RTS_IEC_HANDLE := CryptoGetAlgorithmById(ui32CryptoID:=RtsCryptoID.AES_128_CFB, pResult:=0); _szBlock : ULINT := 16; // Blocksize of ``_hCipher`` => 128 Bit for AES_128_CFB _sKey : SECRET; // 128 Bit Secret Key _szKey : ULINT := 16; // 128 Bit _sInitVector : MESSAGE; // Random Initial Value of Length ``_szBlock`` sPlainText : MESSAGE := 'The red fox has an elongated body and relatively short limbs. The tail, which is longer than half the body length.'; szPlainText : ULINT := TO_ULINT(Standard.LEN(sPlainText)); sCipherText : MESSAGE; sDecipherText : MESSAGE; bsKey : RtsByteString := (ui32MaxLen:=SIZEOF(_sKey), ui32Len:=0, pByData:=ADR(_sKey)); ckKey : RtsCryptoKey; bsInitVector : RtsByteString := (ui32MaxLen:=SIZEOF(_sInitVector), ui32Len:=0, pByData:=ADR(_sInitVector)); bsPlainText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=TO_UDINT(szPlainText), pByData:=ADR(sPlainText)); bsCipherText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=0, pByData:=ADR(sCipherText)); bsDecipheredText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=0, pByData:=ADR(sDecipherText)); Init: BOOL := TRUE; END_VAR IF Init THEN Result1 := CryptoGenerateRandomNumber(ui32NumOfRandomBytes:=TO_UDINT(_szKey), pRandom:=ADR(bsKey)); Result2 := CryptoGenerateRandomNumber(ui32NumOfRandomBytes:=TO_UDINT(_szBlock), pRandom:=ADR(bsInitVector)); ckKey.keyType := RtsCryptoKeyType.KeyType_Key; ckKey.key.byteString := bsKey; Result3 := CryptoSymmetricEncrypt( hAlgo:=_hCipher, pPlainText:=ADR(bsPlainText), key:=ckKey, pInitVector:=ADR(bsInitVector), xEnablePadding:=TRUE, pCipherText:=ADR(bsCipherText) ); Result4 := CryptoSymmetricDecrypt( hAlgo:=_hCipher, pCipherText:=ADR(bsCipherText), key:=ckKey, pInitVector:=ADR(bsInitVector), xEnablePadding:=TRUE, pPlainText:=ADR(bsDecipheredText) ); Init := FALSE; END_IF; ~~~2023-04-03 12:00:22.357000 Ticket #9: Encrypt and Decrypt using AES_128_CFB algorithm IEC Snippets iec-snippets tickets snippets False /tol/iec-snippets/snippets/9/ Ticket Encrypt and Decrypt using AES_128_CFB algorithm False 1 2020-12-14 16:53:47.245000 9 Encrypt and Decrypt using AES_128_CFB algorithm Unlicensed Based on [Crypto Example](https://forge.codesys.com/prj/codesys-example/crypto-example/home/Home/) ~~~ST PROGRAM PLC_PRG VAR Result1, Result2, Result3, Result4 : RTS_IEC_RESULT; _hCipher : RTS_IEC_HANDLE := CryptoGetAlgorithmById(ui32CryptoID:=RtsCryptoID.AES_128_CFB, pResult:=0); _szBlock : ULINT := 16; // Blocksize of ``_hCipher`` => 128 Bit for AES_128_CFB _sKey : SECRET; // 128 Bit Secret Key _szKey : ULINT := 16; // 128 Bit _sInitVector : MESSAGE; // Random Initial Value of Length ``_szBlock`` sPlainText : MESSAGE := 'The red fox has an elongated body and relatively short limbs. The tail, which is longer than half the body length.'; szPlainText : ULINT := TO_ULINT(Standard.LEN(sPlainText)); sCipherText : MESSAGE; sDecipherText : MESSAGE; bsKey : RtsByteString := (ui32MaxLen:=SIZEOF(_sKey), ui32Len:=0, pByData:=ADR(_sKey)); ckKey : RtsCryptoKey; bsInitVector : RtsByteString := (ui32MaxLen:=SIZEOF(_sInitVector), ui32Len:=0, pByData:=ADR(_sInitVector)); bsPlainText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=TO_UDINT(szPlainText), pByData:=ADR(sPlainText)); bsCipherText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=0, pByData:=ADR(sCipherText)); bsDecipheredText : RtsByteString := (ui32MaxLen:=SIZEOF(MESSAGE), ui32Len:=0, pByData:=ADR(sDecipherText)); Init: BOOL := TRUE; END_VAR IF Init THEN Result1 := CryptoGenerateRandomNumber(ui32NumOfRandomBytes:=TO_UDINT(_szKey), pRandom:=ADR(bsKey)); Result2 := CryptoGenerateRandomNumber(ui32NumOfRandomBytes:=TO_UDINT(_szBlock), pRandom:=ADR(bsInitVector)); ckKey.keyType := RtsCryptoKeyType.KeyType_Key; ckKey.key.byteString := bsKey; Result3 := CryptoSymmetricEncrypt( hAlgo:=_hCipher, pPlainText:=ADR(bsPlainText), key:=ckKey, pInitVector:=ADR(bsInitVector), xEnablePadding:=TRUE, pCipherText:=ADR(bsCipherText) ); Result4 := CryptoSymmetricDecrypt( hAlgo:=_hCipher, pCipherText:=ADR(bsCipherText), key:=ckKey, pInitVector:=ADR(bsInitVector), xEnablePadding:=TRUE, pPlainText:=ADR(bsDecipheredText) ); Init := FALSE; END_IF; False False 0 0 0 None i-campbell i-campbell
Last updated: 2023-04-03
Home
tsaroo
wiki
(WikiPage)
This is the personal project of tsaroo. This project is created automatically during user registration as an easy place to store personal data that doesn't need its own project such as cloned repositories.
Last updated: 2023-04-03
(no subject)
IEC Snippets
snippets
(Thread)
Last updated: 2023-04-03
(no subject)
tsaroo
wiki
(Thread)
Last updated: 2023-04-03
Home
jlap
wiki
(WikiPage)
This is the personal project of jlap. This project is created automatically during user registration as an easy place to store personal data that doesn't need its own project such as cloned repositories.
Last updated: 2023-04-03
wiki Discussion
jlap
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03
blog Discussion
jlap
blog
(Discussion)
Forum for blog comments
Last updated: 2023-04-03
(no subject)
jlap
wiki
(Thread)
Last updated: 2023-04-03
Home
bradloren
wiki
(WikiPage)
This is the personal project of bradloren. This project is created automatically during user registration as an easy place to store personal data that doesn't need its own project such as cloned repositories.
Last updated: 2023-04-03
blog Discussion
sturmghost
blog
(Discussion)
Forum for blog comments
Last updated: 2023-04-03
wiki Discussion
bradloren
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03
blog Discussion
bradloren
blog
(Discussion)
Forum for blog comments
Last updated: 2023-04-03
(no subject)
bradloren
wiki
(Thread)
Last updated: 2023-04-03
Home
sturmghost
wiki
(WikiPage)
This is the personal project of sturmghost. This project is created automatically during user registration as an easy place to store personal data that doesn't need its own project such as cloned repositories.
Last updated: 2023-04-03
wiki Discussion
sturmghost
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03
(no subject)
sturmghost
wiki
(Thread)
Last updated: 2023-04-03
wiki Discussion
mariuszforge
wiki
(Discussion)
Forum for wiki comments
Last updated: 2023-04-03