Progress 4GL DECRYPT fails - encryption

I need help. I ENCRYPT json packages with our clients' data with AES_CBC_256 and a different key for each package. Out of about a million data packets generated, the first several dozen cannot be DECRYPT, which returns "?" Subsequent data packets are properly encrypted and can be decrypted properly. MEMPTR is extended by data size + 1024 bytes. The package is first encrypted and then encoded Base64. I do not use IV.
The code below is devoid of all error handling for better readability. Any suggestions?
FUNCTION {&Modul}-encrypt RETURN CHAR(INPUT pInput AS LONGCHAR, INPUT pKey AS RAW, OUTPUT pOut AS LONGCHAR).
DEF VAR mMemPtr AS MEMPTR NO-UNDO.
FIX-CODEPAGE(pOut) = "UTF-8".
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_CBC_256".
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = pkey.
SET-SIZE(mMemPtr) = LENGTH(pInput) + 1024.
mMemPtr = ENCRYPT(pInput) NO-ERROR.
pOut = BASE64-ENCODE(mMemPtr) NO-ERROR.
RETURN "OK".
END.
FUNCTION {&Modul}-decrypt RETURN LONGCHAR(INPUT pInput AS LONGCHAR, INPUT pkey AS RAW).
DEF VAR pOut AS LONGCHAR NO-UNDO.
FIX-CODEPAGE(pOut) = "UTF-8".
DEF VAR mMemPtrIn AS MEMPTR NO-UNDO.
DEF VAR mMemPtrOut AS MEMPTR NO-UNDO.
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_CBC_256".
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = pkey.
mMemPtrIn = BASE64-DECODE(pInput) NO-ERROR.
mMemPtrOut = DECRYPT(mMemPtrIn) NO-ERROR.
COPY-LOB FROM mMemPtrOut TO pOut CONVERT SOURCE CODEPAGE "utf-8" NO-ERROR.
SET-SIZE(mMemPtrIn) = 0.
SET-SIZE(mMemPtrOut) = 0.
RETURN pOut.
END.

Related

How do i get the longest word from 1 variable

Define variable cWord as Character no-undo.
cWord = "Web Development Tool".
Needed OUTPUT
Development
How do i get the longest word from this when its a 1 variable only,
This is a progress4gl code btw
DEFINE VARIABLE cWord AS CHARACTER NO-UNDO.
DEFINE VARIABLE iWord AS INTEGER NO-UNDO.
DEFINE VARIABLE iLongest AS INTEGER NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
DEFINE VARIABLE iLongestLength AS INTEGER NO-UNDO.
DEFINE VARIABLE iEntries AS INTEGER NO-UNDO.
ASSIGN cWord = "Web Development Tool"
iEntries = NUM-ENTRIES (cWord, " ").
DO iWord = 1 TO iEntries:
ASSIGN iLength = LENGTH (ENTRY (iWord, cWord, " ")) .
IF iLength > iLongestLength THEN
DO:
ASSIGN iLongest = iWord
iLongestLength = iLength .
END.
END.
MESSAGE ENTRY (iLongest, cWord, " ")
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
Just because my favorite hammer is a temp-table ;-)
def var cword as longchar no-undo init "Web Development Tool".
define temp-table tt no-undo
field cc as char
.
temp-table tt:read-json(
"longchar",
'~{"tt":[~{"cc":"' + replace( cword, ' ', '"},~{"cc":"' ) + '"}]}'
).
for each tt by length( cc ) descending:
message tt.cc.
leave.
end.
https://abldojo.services.progress.com:443/#/?shareId=5e56f4a84b1a0f40c34b8c3c
If you have two words with same length, this will return first.
DEF VAR iCount AS INT NO-UNDO.
DEF VAR cLongest AS CHAR NO-UNDO.
DEF VAR cString AS CHAR NO-UNDO INIT 'Web Development Tool'.
DO iCount = 1 TO NUM-ENTRIES(cString,' '):
cLongest = (IF LENGTH(ENTRY(iCount,cString,' ')) > LENGTH(cLongest) THEN ENTRY(iCount,cString,' ') ELSE cLongest).
END.
MESSAGE cLongest
VIEW-AS ALERT-BOX INFO BUTTONS OK.

Getting XML data into Temp-Table in Progress 4GL/OpenEdge ABL

so this should be pretty simple. I'm trying to get data from a XML file in an URL and parsing it into a temp-table so I can use the data in the rest of my program. I've written a code but at the end, DISPLAY PAPEL DESCRICAO. doesn't show anything. Am I doing something wrong?
The entire code with the XML link:
DEF TEMP-TABLE CMA NO-UNDO
FIELD PAPEL AS CHAR
FIELD DESCRICAO AS CHAR
FIELD ULTIMO AS DEC
FIELD DIFERENCIAL AS DEC
FIELD VARIACAO AS DEC
FIELD FECHANT AS DEC
FIELD COMPRA AS DEC
FIELD MINIMA AS DEC
FIELD MAXIMA AS DEC
FIELD VENCIMENTO AS INT
FIELD HORA AS CHAR
FIELD DATA AS DATE.
DEF VAR cSourceType AS CHAR NO-UNDO.
DEF VAR cFile AS CHAR NO-UNDO.
DEF VAR cReadMode AS CHAR NO-UNDO.
DEF VAR cSchemaLocation AS CHAR NO-UNDO.
DEF VAR lOverrideDefaultMapping AS LOGICAL NO-UNDO.
DEF VAR cFieldTypeMapping AS CHAR NO-UNDO.
DEF VAR cVerifySchemaMode AS CHAR NO-UNDO.
DEF VAR lReturn AS LOGICAL NO-UNDO.
ASSIGN
cSourceType = "FILE"
cFile = "http://sfeed-cot01.cma.com.br/clientes/cocamar/cbot.xml"
cReadMode = "EMPTY"
cSchemaLocation = ?
lOverrideDefaultMapping = ?
cFieldTypeMapping = ?
cVerifySchemaMode = ?.
lReturn = TEMP-TABLE CMA:READ-XML(cSourceType, cFile, cReadMode,
cSchemaLocation, lOverrideDefaultMapping, cFieldTypeMapping,
cVerifySchemaMode).
IF lReturn THEN
FOR EACH CMA NO-LOCK:
DISPLAY CMA.PAPEL CMA.DESCRICAO.
END.
Any help is much appreciated.
Super close. CMA is not corresponding to the table but to a container tag that could be represented by a Prodataset in this case. Instead just use "QUOTES".
I would not use xml like this in production, you might not have any way to interfere if the source is down etc. I would pull the xml down another way and then load it.
But that's another story...
DEF TEMP-TABLE QUOTES NO-UNDO
FIELD PAPEL AS CHAR
FIELD DESCRICAO AS CHAR
FIELD ULTIMO AS DEC
FIELD DIFERENCIAL AS DEC
FIELD VARIACAO AS DEC
FIELD FECHANT AS DEC
FIELD COMPRA AS DEC
FIELD MINIMA AS DEC
FIELD MAXIMA AS DEC
FIELD VENCIMENTO AS INT
FIELD HORA AS CHAR
FIELD DATA AS DATE.
DEF VAR cSourceType AS CHAR NO-UNDO.
DEF VAR cFile AS CHAR NO-UNDO.
DEF VAR cReadMode AS CHAR NO-UNDO.
DEF VAR cSchemaLocation AS CHAR NO-UNDO.
DEF VAR lOverrideDefaultMapping AS LOGICAL NO-UNDO.
DEF VAR cFieldTypeMapping AS CHAR NO-UNDO.
DEF VAR cVerifySchemaMode AS CHAR NO-UNDO.
DEF VAR lReturn AS LOGICAL NO-UNDO.
ASSIGN
cSourceType = "FILE"
cFile = "http://sfeed-cot01.cma.com.br/clientes/cocamar/cbot.xml"
cReadMode = "EMPTY"
cSchemaLocation = ?
lOverrideDefaultMapping = ?
cFieldTypeMapping = ?
cVerifySchemaMode = ?.
lReturn = TEMP-TABLE QUOTES:READ-XML(cSourceType, cFile, cReadMode,
cSchemaLocation, lOverrideDefaultMapping, cFieldTypeMapping,
cVerifySchemaMode).
DISP lReturn.
IF lReturn THEN
FOR EACH QUOTES NO-LOCK:
DISPLAY QUOTES.PAPEL QUOTES.DESCRICAO.
END.

Python Write Personal User ID using RC522

I'm struggling in using Python3 for writing and reading personal user id in rc522. Here I want to write (for example, 123) in the rfid based on the input. However, after I write '123', the python says
can't concat list to bytearray.
Please, help. Thank you :D
info = input("Personal ID")
info = int(info)
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A,8,key,uid)
if status == MIFAREReader.MI_OK:
data = bytearray(16)
value = format(info,'x')
while (8 > len(value)):
value = '0' + value
data[0:8] = bytearray.fromhex(value)
MIFAREReader.MFRC522_Write(8,data)
def (self,blockAddr,writeData)
buff = []
buff.append(self.PICC_WRITE)
buff.append(blockAddr)
crc = self.CalulateCRC(buff)
buff += crc
(status,backData,backLen) = self.MFRC522_ToCard(
self.PCD_TRANSCEIVE,buff
)
buff = writeData[0:8]
crc = self.CalulateCRC(buff)
buff += crc /////the error is pointed here
(status,backData,backLen) = self.MFRC522_ToCard(
self.PCD_TRANSCEIVE,buff
)
if status == self.MI_OK:
return True

Issues with Hex.encodeHexString(byte[] hexStringByteArray);

I was used Hex.encodeHexString(byte[] hexStringByteArray); api for convert byte array to String but in two different situations not able to get the excepted values.
Excepted String tcpPort = "1443";
In byte array [5,-93] --> In Hex String : 05a3
byte[] value1 = new byte[]{[5, -93]};
String tcpPort1 = Hex.encodeHexString(value1); // Incorrect value 05a3
Excepted String bufferSize = "0578";
In byte array [[5, 120] --> In Hex String : 0578
String bufferSize = "0578"; // in byte array [5,120]
byte[] value2 = new byte[]{[5, 120]};
String bufferSize = Hex.encodeHexString(value1); --- Correct value 0578
1 is incorrect and 2 is correct. Please help on this. I have to correct both values in same way.

ifnull not enough for testing for numerical rs

I have a function, which is supposed to return zero, if the input cannot be converted to an integer.
But sometimes it fails, if the field from a resultset is not a proper value, whatever it is.
Function nulblank(str)
dim val
if IsNull(str) then
val=0
else
str = trim(str)
if isNumeric(str) then
val = cDbl(str)
else
val = 0
end if
end if
nulblank = val
end function
I get an error 0x80020009 on str = trim(str)
This function is only called on
set rs = conn.execute(sql)
i = nulblank(rs("somefield"))
How can I make this function "failsafe", so it never dies, but returns 0 on "bad" values?
I guess I could do on error resume next and if Err.Number <> 0 then something.
But what can be in a rs("somefield") which is not null, but cannot be trim()'ed?
That error usually relates to an empty recordset.
You should check that the recordset has a row before attempting to retrieve a column value, eg:
set rs = conn.execute(sql)
if not rs.eof then
i = nulblank(rs("somefield"))
end if

Resources