Encryption j2me弹性城堡aes与典型aes不同
您好,正在使用j2me bouncy castle aes进行编码和解码。它在设备上运行良好,但我注意到结果与通常的aes加密不同。因此,一旦使用bouncy castle aes加密,就无法与服务器共享信息。例如bouncy castle aes hello=01Fvdltwa2VKVPCH3ueHAA==但使用典型的aes加密hello=0tUfc3Qwod0qw1kVaI8ksw===。 有人经历过这种情况吗?我怎样才能解决这个问题?。注意:我的加密密钥是re5fdh3jxlow5ncc . 我需要回复 这是我的密码:Encryption j2me弹性城堡aes与典型aes不同,encryption,java-me,aes,bouncycastle,Encryption,Java Me,Aes,Bouncycastle,您好,正在使用j2me bouncy castle aes进行编码和解码。它在设备上运行良好,但我注意到结果与通常的aes加密不同。因此,一旦使用bouncy castle aes加密,就无法与服务器共享信息。例如bouncy castle aes hello=01Fvdltwa2VKVPCH3ueHAA==但使用典型的aes加密hello=0tUfc3Qwod0qw1kVaI8ksw===。 有人经历过这种情况吗?我怎样才能解决这个问题?。注意:我的加密密钥是re5fdh3jxlow5ncc
import com.codename1.util.Base64;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
/**
*
* @author SAMUEL
*/
public class Tester {
static String strEnc = "Hi This is my String";
final static String strPassword = "password12345678";
private static byte[] cipherData(PaddedBufferedBlockCipher cipher, byte[] data)throws Exception
{
int minSize = cipher.getOutputSize(data.length);
byte[] outBuf = new byte[minSize];
int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
int length2 = cipher.doFinal(outBuf, length1);
int actualLength = length1 + length2;
byte[] result = new byte[actualLength];
System.arraycopy(outBuf, 0, result, 0, result.length);
return result;
}
private static byte[] decrypt(byte[] cipher, byte[] key, byte[] iv) throws Exception
{
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(false, ivAndKey);
return cipherData(aes, cipher);
}
private static byte[] encrypt(byte[] plain, byte[] key, byte[] iv) throws Exception
{
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(true, ivAndKey);
return cipherData(aes, plain);
}
public static void main(String [] args) throws Exception{
byte[] enc= encrypt(strEnc.getBytes(),"password12345678".getBytes(), "password12345678".getBytes());
String encbase = Base64.encode(enc);
String encrypted =new String(encbase.getBytes(), "UTF-8");
System.out.println("Encrypted is:"+encbase);
byte[] decbase = Base64.decode(encrypted.getBytes());
byte[] dec= decrypt(decbase,"password12345678".getBytes() , "password12345678".getBytes());
System.out.println("Decrypted file is:"+new String(dec, "UTF-8"));
}
}
但是请注意,结果与典型的aes加密不同没有代码,没有帮助。这是我的代码:…@SanAce不要将我们链接到其他地方。请编辑您的问题,并将您的代码发布为演示您的问题的。我编辑了我的问题。。我将接受关于如何解决加密输出问题差异的任何回复。如果您在问题中做了一些工作,我们可能也想在这方面做一些工作。我不打算把这些都格式化。白费力气。