I am trying to encrypt a string
The string should then be encrypted using AES(block size 128-bit) in CBC mode with PKCS#5 padding using the provided password as both the key and initialisation vector and encode the result in hex (making sure the letters are in upper case).
Prepend the ‘@’ sign to the beginning of the encoded result.
my code is
#!/usr/bin/perl print "content-type: text/html \n\n"; use strict; use warnings; use Crypt::CBC; use Crypt::Cipher::AES; my $prepend = '@'; my $user_string = 'VendorTxCode=TxCode-1310917599-223087284&Amount=36. +95&Currency=GBP&Description=description&CustomerName=FnameSurname&Cus +tomerEMail=customer@example.com&BillingSurname=Surname&BillingFirstna +mes=Fname&BillingAddress1=BillAddress Line1&BillingCity=BillCity&Bill +ingPostCode=W1A1BL&BillingCountry=GB&BillingPhone=447933000000&Delive +ryFirstnames=Fname&DeliverySurname=Surname&DeliveryAddress1=BillAddre +ssLine 1&DeliveryCity=BillCity&DeliveryPostCode=W1A1BL&DeliveryCountr +y=GB&DeliveryPhone=447933000000&SuccessURL=https://example.com/succes +s&FailureURL=https://example.com/failure'; my $key = '55a51621a6648525'; my $iv = '55a51621a6648525'; my $cipher = Crypt::CBC->new( -cipher => 'Crypt::Cipher::AES', -key => $key, -iv => $iv, -padding => 'standard', -header => 'none', -blocksize => '16' ); my $encrypted = uc $cipher->encrypt_hex($user_string); my $decrypted = $cipher->decrypt_hex($encrypted); print $prepend,$encrypted, "\n"; print $decrypted, "\n";
The encrypted result should be
but I get2DCD27338114D4C39A14A855702FBAB2EF40BCAC2D76A3ABC0F660A07E9C1C921C2C75 +5BA9B59C39F882FBF6DFED114F23141D94E50A01A665B1E31A86C07CACD1BB8EF5B6C +F2C23D495CD 79F9C0F678D61773E7A1AA30AA5B23D56503FC0B52AC0694A8C341263D2C5FE1BAD93B +DB94726761E155E900448F644AF1F67BE1AC77E852B9D90809A44F258E9478B6D8C1C +4ED58759263E7DBF 8871C6592287C0358F36F4EEC326CEDDD440DA2FED8AB35F1B630A5C6FA671E4D78CC8 +CACECF9DFDC31D6C5EC8270FB21E297E2C2E14F99A04223EFFD4F0006D440E78A3D2C +7140EC8F123D24 7B75E7482AE98858DA34D37EDE6D7C69AA74391F559305CF675ADB3615244A107ABBB6 +AF26E29A2FFA059B12688D90FE09E0DE069325BFF3587A695F5DA36E4809B69CC9A37 +034F166B63B5A62 B986F4DA34E9AC9516AFDE70642EC7DAD1AEBA93A1F347D6AC7046E967DCBFE7ACFCEE +5DAFC0B29F1765032B3060EBE565CBD57D092075D15CF12725199C688605B2E0F1056 +98CE3ADD04361C A9D620C187B90E3F9849445B5C3C0FDF1768BFFD61F97E51316826F4F10E0E3E668F0A +9F5ED9CCDA6F2C7CC957F12DB48F9041482E3D035E7A91852C404BFA35FED947E71F5 +7B871DFAC6AF4FF2 9F4513A4A80B2D7ECC9D19D47ED04FA99CDFC881DFA771E1EA4F3F9B2C5AC673EF3DA2 +699A309CC8522993A63CB8D45D3CDF09B1DFDC573CD19679B250AD672450B5042F201 +670B464505DCAE F59E2C67ABACC9AE2EEE793CE191FEBF66B8FAF4204EFFB359246B9C99FB52805C4637 +5FF35140F74707FBC73C7731A28A2C883A
am I over simplifying the encryption method or am I misunderstanding what has to be done.@4AA9DF4F8981CCD08D468C3E4468BB9D770A429A2BBA4053AC59B03B7BCC2EB1604B2 +13489AB4DF1AD39D6A0050806AB667945BFE18173C769773DAA957A0950F7AAAB8BBC +E90AB63B836A96D2B91842AD43662CED25175E83C57B689E3A2FAB5BB502329434F73 +5847CDBF6C98719E5A24F4E89B529DE86B714BC0BA5F4AE6BC1DE1C089DFFF088F03A +2831891373FBAA6D5E0CA96AD3111DB1B4EBE04CC581F54963360CB67055359B1FC86 +06AD5435A27D6474747FA44402879D2A18C20ABC9639D07C31B5AFC2CB015268955EC +C897651094DC8C34C764D2E74EE23FDD9892DCB7A6F260D0C8999E9F403F0917B5EE4 +16D56A61434DE1FD2F3357461C3B09E3892D5EE0D4D1459ACD667DBD0B98A40550C8C +73815451FE5A24FA63325EF0D2A3E89560462957EDA6862808FFABE0F50ED425DA64E +9625FD2374FD2EA4BAF0FCCE868FDEEC2D87058C8E0F8E19DF01FBBD252F10FFA2F7E +C09C0256A3BE36EC4D6D22B79424AB2F5CD500B611C669712DB3A70AABE50B2BC494E +72C9F9A229C01CE6156DFDC3CA1838AF2C8153174A0C8ED685BC9A72DC35B51CEBAA9 +498F1F1D5A8D8B6AD2BAE7645E739D0D05C094F7349881FE4B1E2A5ACD57CB223B675 +B6C0509A3675B874B562B71D3A07127950BF17B3579C32496002ED25DD901CF3E6F96 +45AB38113032873AF55D45BDEEABE291869121416466AB804A069E1B902E821797563 +46C61431CEE7527C44A209C7FDA3DDF723C7DE98A9CD2DBE1B1BCE2D169EF074989B0 +201BF1F6E6936EE8C47ACC374DE145A4FBBC569427DA6DCA
In reply to Encrypt using AES(block size 128-bit) in CBC by mikemc24
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |