错误:密钥长度不是128/192/256位。 初始化时在这里:cipher.Init(true,keyParamWithIv); //抛出错误消息
enter code here
公共字符串PIDEncrpt(byte [] inputBytes,byte []键) {
//Set up
AesEngine engine = new AesEngine();
byte[] iv = new byte[16]; //for the sake of demo
CbcBlockCipher blockCipher = new CbcBlockCipher(engine);
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher, new Pkcs7Padding());
Debug.WriteLine(iv.Length);
Debug.WriteLine(cipher.GetBlockSize());
KeyParameter keyParam = new KeyParameter(key);
ParametersWithIV keyParamWithIv = new ParametersWithIV(keyParam, iv, 0, 16) ;
cipher.Init(true, keyParamWithIv); //Error Message thrown
byte[] outputBytes = new byte[cipher.GetOutputSize(inputBytes.Length)]; //cip
int length = cipher.ProcessBytes(inputBytes, outputBytes, 0);
cipher.DoFinal(outputBytes, length); //Do the final block
string encryptedInput = Convert.ToBase64String(outputBytes);
return encryptedInput;
}