So any updates by i series experts on this problem:-
Input data(given as base64
format):-u3VtNgfyWU9faZcIaa8ZWbE5UZCf7yA4MyW0ghflt9dNQNDpCcgMZiG/kXPECHL93B4iKiODHxxdVA=='
Key:-661e275OIM1ULYLJ
program to decrypt it using AES 128 algorithm:-
*************** Beginning of data
*************************************
0001.00 HDFTACTGRP(*NO) BNDDIR('QC2LE') option(*srcstmt : *nodebugio)
0002.00 h actgrp(*new)
0003.00 ddata s 89a
inz('u3VtNgfyWU9faZc3Iaa8ZWbE5UZC
0004.00 d
-7yA4MyW0ghflt9dNQNDpCcgMZiG/kXPE
0005.00 d -2CHL93B4iKiODHxxdVA==')
0006.00 dsecretkey s 16a varying
inz('661e275OIM1ULYLJ')
0007.00 dencrypted s 16a
0008.00 dascharacters s 32a
0009.00 dAES_CONTROL DS Qualified
0010.00 dfunctionid 2a
0011.00 ddatalen 5u 0
0012.00 doperation 1a
0013.00 dmode 1a
0014.00 dblocklen 1a
0015.00 dmaclen 1a
0016.00 dinitVector 32a
0017.00 dreserved 7a
0018.00 dkeyoption 1a
0019.00 dkeyschedule *
0020.00 dkey 32a
0021.00 dcipher pr extproc('_CIPHER')
0022.00 dreceiver *
0023.00 dcontrol 96a
0024.00 dsource *
0025.00 dcvthc pr extproc('cvthc')
0026.00 drcvhex * VALUE
0027.00 dsrcchr * VALUE
0028.00 drcvlen 10i 0 VALUE
0029.00 dhex s 2a
0030.00 dp_recv s *
0031.00 dp_src s *
0032.00
0033.00 /FREE
0034.00 AES_Control = *ALLx'00';
0035.00 AES_Control.functionID = x'0015';
0036.00 AES_Control.datalen = %size(data);
0037.00 AES_Control.operation = x'00';
0038.00 AES_Control.mode = x'00'; // 0=ECB
0039.00 AES_Control.blockLen = x'10'; // 16
0040.00 AES_Control.MACLen = x'00'; // 0
0041.00 AES_Control.keyOption = x'10';
0042.00
0043.00 AES_Control.key = secretKey;
0044.00 p_recv = %addr(encrypted);
0045.00 p_src = %addr(data);
0046.00 cipher( p_recv : AES_Control : p_src);
0047.00
0048.00 p_recv = %addr(asCharacters);
0049.00 p_src = %addr(encrypted);
0050.00 cvthc ( p_recv : p_src : %size(asCharacters));
0051.00 dsply asCharacters;
0052.00 data = *blanks;
0053.00
0054.00 AES_Control = *ALLx'00';
0055.00 AES_Control.functionID = x'0015';
0056.00 AES_Control.datalen = %size(data);
0057.00 AES_Control.operation = x'01'; //
0058.00 AES_Control.mode = x'00'; // 0=ECB
0059.00 AES_Control.blockLen = x'10'; // 16
0060.00 AES_Control.MACLen = x'00'; // 0
0061.00 AES_Control.keyOption = x'10'; // use
0062.00
0063.00 AES_Control.key = secretKey;
0064.00 p_recv = %addr(data);
0065.00 p_src = %addr(encrypted);
0066.00
0067.00 cipher( p_recv : AES_Control : p_src);
0070.00 *inlr = *on;
0071.00 /end-free
******************
But it is not working and I am getting error as followings:-
Additional Message Information
Message ID . . . . . . : MCH5601 Severity . . . . . . . : 40
Message type . . . . . : Diagnostic
Date sent . . . . . . : 19-10-07 Time sent . . . . . . :
12:36:12
Message . . . . : Template value not valid for instruction.
Cause . . . . . : The location of the value is template with an offset
to
field in bytes X'0002', an offset in field in bits X'0000', a length of
field of 2, and an instruction operand number of 2. The reason code is
X'0000'. If the reason code is X'0000', a reason code may not be
available.
Any one can please advise why is it not working and what to do to
make it work where as data i have put as base64 encoded data only and also
using complex key to decrypt it still it's not getting decrypted and giving
error where as if i put below code it works very well:-
H DFTACTGRP(*NO) BNDDIR('QC2LE') option(*SRCSTMT: *NODEBUGIO)
H ACTGRP(*NEW)
D data s 16A inz('My coded message')
D secretKey s 16A varying inz('Secret Password')
D encrypted s 16A
D asCharacters s 32A
D AES_Control ds qualified
D functionID 2A
D dataLen 5U 0
D operation 1A
* x'00' = Encrypt, x'01' = Decrypt
D mode 1A
* x'00' = ECB, x'01' = CBC
D blockLen 1A
D MACLen 1A
D initVector 32A
D reserved 7A
D keyOption 1A
* x'00'=KeySched. x'10'=16-byte, x'18'=24-byte, x'20'=32-byte key
D keySchedule *
D key 32A
D cipher PR extproc('_CIPHER')
D receiver *
D control 96A
D source *
D cvthc Pr ExtProc( 'cvthc' )
D RcvHex * Value
D SrcChr * Value
D RcvLen 10i 0 Value
D Hex s 2a
D p_recv s *
D p_src s *
/free
// The following will encrypt "data" using the AES
// algorithm with the secret key "key", and place
// the result into "encrypted"
AES_Control = *ALLx'00';
AES_Control.functionID = x'0015';
AES_Control.datalen = %size(data);
AES_Control.operation = x'00'; // 0=Encrypt,1=Decrypt
AES_Control.mode = x'00'; // 0=ECB
AES_Control.blockLen = x'10'; // 16
AES_Control.MACLen = x'00'; // 0
AES_Control.keyOption = x'10'; // use 16-byte key
AES_Control.key = secretKey;
p_recv = %addr(encrypted);
p_src = %addr(data);
cipher( p_recv : AES_Control : p_src);
p_recv = %addr(asCharacters);
p_src = %addr(encrypted);
cvthc ( p_recv : p_src : %size(asCharacters));
dsply asCharacters;
// The following will decrypt "encrypted" using the AES
// algorithm with the secret key "key", and place the
// result in "data". We blank out data ahead of time
// to ensure that it's contents aren't carried over from
// the code above.
data = *blanks;
AES_Control = *ALLx'00';
AES_Control.functionID = x'0015';
AES_Control.datalen = %size(data);
AES_Control.operation = x'01'; // 0=Encrypt,1=Decrypt
AES_Control.mode = x'00'; // 0=ECB
AES_Control.blockLen = x'10'; // 16
AES_Control.MACLen = x'00'; // 0
AES_Control.keyOption = x'10'; // use 16-byte key
AES_Control.key = secretKey;
p_recv = %addr(data);
p_src = %addr(encrypted);
cipher( p_recv : AES_Control : p_src);
dsply data;
*inlr = *on;
/end-free
Thanks
On Fri, Oct 4, 2019, 16:42 Rishi Seth <rishiseth99@xxxxxxxxx> wrote:
1.so make this work action item is first translate that long ecoded data
in my example here to EBCDIC then feed it to your cipher program to test
it för decryption?
2.or after cipher decrypts this encoded data can at that point of time
also could it be translated in EBCDIC?
3.this is the forum för sporting out out out queries and not to insult
anyone so all have rights to sortout their queries even though links
websites are there and even whole Google is there to educate ourselves even
though i believe this forum is designer to help iseriesProfessional guys
isn't it?
Secondly i have already been trying each and every single approach advised
on this mail chain but IF something is falling and i äm stuck åt somewhere
then i dö think by asking those queries i äm not making any wrong here.
On Fri, Oct 4, 2019 at 4:21 PM Mark Waterbury <
mark.s.waterbury@xxxxxxxxxxxxx> wrote:
Rishi,
Highlighting and "colors" etc., and "embedded images" and attachments,
never make the trip through the list servers at midrange.com -- never
have, never will. You could post an image at e.g. imgur and then paste a
link to it in your replies to these lists.
As to your problems with the code, the problem is not with the IBM i or
those APIs, but with you. You cannot simply take any old sample code, and
just cut and paste it, willy-nilly, and expect it to work.
Myself and others have tried to explain to you, in numerous replies to
this thread, both on the list and "off-list" (due to attachments), there
are multiple issues with your approach to this problem. Here are the top
ones:
#1. that web site you frequently reference returns results in a BASE64
encoding. You have made no attempt to deal with that, yet you seem to think
you can just feed that data into the "cipher()" MI built-in function, or
the SQL DECRYPT_CHAR function, and get some meaningful results? (In
fact, that web site offers an option to return the data in HEX notation;
that should be easier for you to work with.)
#2. that web site, like most web pages, works in ASCII or UTF-8. So the
data returned is also encoded as UTF-8. Yet you seem to think you can just
type that into a string literal constant value (INZ ...) in ILE RPG IV, and
feed that into the "cipher()" built-in function, and get back meaningful
results. Again, you have made no attempt to deal with that issue, e.g. by
translating the data into EBCDIC, either before or after you decrypt it.
#3. you have now repeatedly asked many questions related to this, and
many on this list have provided some very good answers, by providing links
to various documentation and sample code and web sites, etc. -- and yet,
you continue to just blindly pound away at this, apparently by cutting and
pasting various snippets of code, and somehow you seem to expect it all to
"just work." It appears that you have made very little effort to read
any documentation or search the web to find answers for yourself -- you
just keep asking questions here, over and over, expecting someone to
provide you with a solution.
That is not the best way to get good results from these lists. I suggest
you read this web page, that explains how to ask better questions in order
to get better answers from these kinds of lists, groups and forums:
http://catb.org/~esr/faqs/smart-questions.html
If you continue to just keep asking the same dumb questions, over and
over again, most readers will conclude that you are a clueless "noob" and
simply ignore your questions and your continued pleading for assistance.
I hope this helps you.
Sincerely,
Mark S.Waterbury
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.