Java AES-128 ECB加密

时间:2018-11-15 15:34:51

标签: java encryption aes

我已经收到来自AT5(Atrack)联合使用AES-128 ECB加密编码的消息,这是十六进制的密钥(33333838000000000000000000000000) 原始密钥在字符串“ 3388”中 这是我收到的密码,但我将其转换为十六进制

每当我尝试解密邮件时,都会遇到此异常:

  

解密时出错:javax.crypto.IllegalBlockSizeException:使用填充密码解密时,输入长度必须是16的倍数。

这是我的代码:

    orginalString 

 ?U??????}MgD?R???`????
#?j????g:N???@???$=???r?u?>~??Qh,?N?????3?8:?-E??;?b<J??I?v{?'o?m[?|?CY?n????K????>?ã??<?,????  ??f?'???}&?}?7r%??93??!u?0D?3Ig|??%'????*??`?Y^?M?4J?I?>?tIu???;?RR;2??{nrl??us
?R?F?oi????



String strToDecrypt = "E255898281B7C0B67D4D6744DB52FA1789F760B99B86A40A1F238B6ABCC690C1C9673A4E07EA03F79B40B2ACC8243DD098F4B10E72BA75CE3E7EE50F935168042CC74EA2F4BBE3D833F4383AE02D45C0119C3BC8623C4AD5189249FAB0BB767BA2276FB56D5BF27CE017435901DD8F6EC9DECD05B74BF51A99B1933E89C3A3AD06CA893CE72CDDEAE5F509E2D01B66A02717AADD0C917D26BA7DB1377225CCF23933E5F92175BD3044C63349677CEBC6251B27BE1FC9FD7FC32A0785F36019C2595E1EE783B64DB2344A14CE49C63EAB74174975FCE1C53BD95252113B0332CBD7A37B6E726CCFF675730DB052B14605E36F69AF11E8F3D2002D8BABEFFF508187E4C176329A3ABE08CF2B9A9F4812CF4084BACE87AD116F49C2ACD449767E758CE9184C60268AE3AAEADA052C91BF16241682E333671AC209D5BDC34CFD2B2D0C8D6D795D36A5FBD707FB56F71B3740BA86B1CEAC6E784E8E2B999CC6C9260A13F697A115C80F29C5AA38E95964731073CB051BB8A201EBAE6443A057AA69CFF41C9A593F88E2D6A712107EABCDE7042134F818268BF31896072C1B399B878BACCECC096F79A8D1835C2766EA639341E4AB22820D5AAD0F202BC896BD6C6F4D1FB1873C5BE06278D11E67F577D0120E054971088E7DB7E3A8139B20C6E22B86205BC0F4778A1DA0D6E50416FCE55DBC576A9F907FC706148204CA3C79993A4F37756427871C12EB379B4BFA0A518FFCA2BC698B1CA68AC9B3548B241C12669CEFAC9C8ECDB7B5A8149B";
secretKey = new SecretKeySpec("33333838000000000000000000000000".getBytes("UTF-8"), "AES");

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] cipherResult = cipher.doFinal(Base64.decodeBase64(strToDecrypt));

1 个答案:

答案 0 :(得分:1)

您的strToDecrypt似乎是十六进制编码,而不是 base64编码 ..,因此您需要在解密之前对其进行十六进制解码,而不是base64解码。但是实际上,如果您对数据进行了十六进制解码,则您加密的数据最终也会具有无效的大小。您的十六进制字符串为1200十六进制字符= 600字节= 16字节的37.5 AES块..您的数据似乎有问题..

此外,您的密钥也是十六进制编码的,因此您需要对它进行十六进制解码..不只是做getBytes(..)