我们正在通过 ac# 应用程序从该代码中加密/解密我们组织的文档
var msData = new MemoryStream();
CryptoStream cs = null;
if (inputFileStream.CanSeek)
inputFileStream.Seek(0, SeekOrigin.Begin);
try
{
long inputFileLength = inputFileStream.Length;
var byteBuffer = new byte[4096];
long bytesProcessed = 0;
int bytesInCurrentBlock = 0;
var csRijndael = new RijndaelManaged();
switch (action)
{
case CryptoAction.Encrypt:
cs = new CryptoStream(msData, csRijndael.CreateEncryptor(this.Key, this.IV), CryptoStreamMode.Write);
break;
case CryptoAction.Decrypt:
cs = new CryptoStream(msData, csRijndael.CreateDecryptor(this.Key, this.IV), CryptoStreamMode.Write);
break;
}
while (bytesProcessed < inputFileLength)
{
bytesInCurrentBlock = inputFileStream.Read(byteBuffer, 0, 4096);
cs.Write(byteBuffer, 0, bytesInCurrentBlock);
bytesProcessed += bytesInCurrentBlock;
}
cs.FlushFinalBlock();
return msData.ToArray();
}
catch(Exception ex)
{
new Com.Library.SqlLog().InsertSqlLog(Auth.currentMemberInfo.LoginId, MethodInfo.GetCurrentMethod().Name, ex);
return null;
}
它工作正常。现在我正在创建一个 Java 应用程序,它也应该解密这些文档。最初我试图用这段 Java 代码解密文档
try{
AlgorithmParameterSpec paramSpec = new IvParameterSpec(IV);
Cipher cipher = Cipher.getInstance("AES");
SecretKeySpec key = new SecretKeySpec(keyGen, "AES");
cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
byte[] output = new BASE64Decoder().decodeBuffer(new String(convertDocToByteArra("//Path/somePDF.pdf")));
byte[] decrypted = cipher.doFinal(output);
convertByteArrayToDoc(decrypted);
}catch(Exception e){
e.printStackTrace();
}
现在这是我的问题。我将其作为初始化向量传递
static byte IV[] = new byte[] {0x0E,0x15,(byte)0xC4,(byte)0xBB,
(byte)0xEE,(byte)0xDF,0x72,0x0C,0x4F,0x7E,(byte)0xBE,0x67,0x4A,(byte)0xB6,0x45,(byte)0xDE};
这是一个关键
static byte[] keyGen = new byte[]{0x78,(byte)0x9C,(byte)0xF1,0x01,0x12,0x31,(byte)0xCD,0x1E,0x1F,0x16,0x54,0x19,0x1D,(byte)0xFF,(byte)0xC7,
0x00,0x51,(byte)0xBF,(byte)0xFD,0x31,(byte)0xE1,(byte)0xA1,(byte)0xDC,(byte)0xC9,0x23,0x49,(byte)0xAD,0x11,0x16,0x17,0x1D,0x1F};
但是当我运行这个程序时,它会抛出下面给出的异常
java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1023)
at javax.crypto.Cipher.implInit(Cipher.java:789)
at javax.crypto.Cipher.chooseProvider(Cipher.java:848)
at javax.crypto.Cipher.init(Cipher.java:1347)
at javax.crypto.Cipher.init(Cipher.java:1281)
at DecryptAspEncryptedDocs.main(DecryptAspEncryptedDocs.java:80)
现在我被困在这里,不知道该怎么做。任何帮助将不胜感激。
编辑 1:
我已经看到了这个问题,并且 jar 被放置在 jre/lib/security 和 jdk/lib/security 中。但是问题仍然存在并且抛出illegal key size
异常