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

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

如何將 Java AES - CBC 與 PKCS5 填充更改為 PHP

如何將 Java AES - CBC 與 PKCS5 填充更改為 PHP

蝴蝶刀刀 2022-05-21 16:53:57
我正在嘗試將 JAVA 加密更改為 PHP 并產(chǎn)生完全相同的結(jié)果。我有以下準(zhǔn)則。AES - CBC 與 PKCS5 填充對(duì)稱加密方案:加密密鑰大小為 128 位大小。初始化向量(IV):-新的隨機(jī) IV 將在每個(gè)請(qǐng)求中使用。-在單個(gè) Web 服務(wù)請(qǐng)求中,在加密所有加密字段時(shí)將使用相同的 IV。-此 IV 將在名稱為“IV”的 SOAP Header 中傳遞。IV 值將采用 Base64 編碼。我試過(guò)這個(gè)https://gist.github.com/thomasdarimont/fae409eaae2abcf83bd6633b961e7f00public class AESEncryptionUtil {public static final String CLASS_NAME = AESEncryptionUtil.class.getName(); private static final int KEY_SIZE = 16;private static final String ALGORITHM_AES = "AES";public final static String ALGORITHM_AES_CBC = "AES/CBC/PKCS5Padding";private static Key generateKey(String keyValue) throws Exception { Key key = null ;if (keyValue!=null && keyValue.length()==KEY_SIZE){byte[] byteKey = keyValue.substring(0, KEY_SIZE).getBytes("UTF-8");  key = new SecretKeySpec(byteKey, ALGORITHM_AES);}else{System.out.println("Not generating the Key!! "+keyValue); }return key; }/*** Return Base64 Encoded value of IV ** @param keyValue * @return* @throws Exception */public static String generateIV(String keyValue) throws Exception { String iv = null ;Key key = generateKey(keyValue); if (key!=null){Cipher cipher = Cipher.getInstance(ALGORITHM_AES_CBC); cipher.init(Cipher.ENCRYPT_MODE, key); AlgorithmParameters params =     cipher.getParameters();iv = new BASE64Encoder().encode(params.getParameterSpec(IvParameterSpec.class).getIV());  }else{System.out.println("No IV generated ...");}return iv; }/*** Method to perform encryption of given data with AES Algorithm / Key and IV. * @param encKey -*Encryption Key value * @param plainVal -*Value to be encrypted * @return - encrypted String Value * @throws   Exception*/
查看完整描述

1 回答

?
揚(yáng)帆大魚(yú)

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊

我設(shè)法得到一些工作


<?php

$string = "online1234";

$key = "haskingvista127$";


$iv  = base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-128-cbc')));


$encodedEncryptedData = base64_encode(openssl_encrypt($string, "AES-128-CBC", $key, OPENSSL_RAW_DATA, base64_decode($iv)));


$decryptedData = openssl_decrypt(base64_decode($encodedEncryptedData), "AES-128-CBC", $key, OPENSSL_RAW_DATA, base64_decode($iv));


?>

希望這可以幫助別人


查看完整回答
反對(duì) 回復(fù) 2022-05-21
  • 1 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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