第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Java AES并使用我自己的密鑰

Java AES并使用我自己的密鑰

瀟湘沐 2019-10-24 10:30:23
我想使用我自己的密鑰使用AES加密字符串。但是我在密鑰的位長度上遇到了麻煩。您能否查看我的代碼并查看需要修復(fù)/更改的內(nèi)容。public static void main(String[] args) throws Exception {    String username = "bob@google.org";    String password = "Password1";    String secretID = "BlahBlahBlah";    String SALT2 = "deliciously salty";    // Get the Key    byte[] key = (SALT2 + username + password).getBytes();    System.out.println((SALT2 + username + password).getBytes().length);    // Need to pad key for AES    // TODO: Best way?    // Generate the secret key specs.    SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");    // Instantiate the cipher    Cipher cipher = Cipher.getInstance("AES");    cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);    byte[] encrypted = cipher.doFinal((secrectID).getBytes());    System.out.println("encrypted string: " + asHex(encrypted));    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);    byte[] original = cipher.doFinal(encrypted);    String originalString = new String(original);    System.out.println("Original string: " + originalString + "\nOriginal string (Hex): " + asHex(original));}現(xiàn)在,我得到一個(gè)異?!?無效的AES密鑰長度:86個(gè)字節(jié) ”。我是否需要墊鑰匙?我該怎么辦?還需要為ECB或CBC設(shè)置任何內(nèi)容嗎?
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 2579 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)