저는 Android 앱을 개발 중입니다. 불행히도 나는 호환성 문제가있다. 내 소스 코드는 펌웨어 4.1에서 작동하지만 펌웨어 2.2가있는 장치와 충돌합니다. 이 오류는 ObjectInputStream으로 인해 발생하는 "ClassNotFoundException"인 것 같습니다. 암호화 및 암호 해독을위한안드로이드 2.2에서 RSA 암호화/암호 해독이 충돌합니다.
내 소스 코드 :
private Key getPublicKey() {
try {
InputStream fis = activity.getResources().openRawResource(R.raw.publick);
ObjectInputStream ois = new ObjectInputStream(fis);
Key RSApublicKey = (Key) ois.readObject();
return RSApublicKey;
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
private Key getPrivateKey() {
try {
InputStream fis = activity.getResources().openRawResource(R.raw.privatek);
ObjectInputStream ois = new ObjectInputStream(fis);
Key RSAprivateKey = (Key) ois.readObject();
return RSAprivateKey;
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
Log.e("error", "Error: " + e);
e.printStackTrace();
}
return null;
}
public byte[] encrypt(String data) {
byte[] encrypted = null;
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, getPublicKey());
encrypted = cipher.doFinal(data.getBytes());
}
catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
catch (BadPaddingException e) {
e.printStackTrace();
}
catch (InvalidKeyException e) {
e.printStackTrace();
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
catch (NoSuchProviderException e) {
e.printStackTrace();
}
return encrypted;
}
public String decrypt(byte[] encrypted) {
byte[] decrypted = null;
try {
Cipher cipher;
cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
decrypted = cipher.doFinal(encrypted);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
catch (InvalidKeyException e) {
e.printStackTrace();
}
catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
catch (BadPaddingException e) {
e.printStackTrace();
}
catch (NoSuchProviderException e) {
e.printStackTrace();
}
return new String(decrypted);
}
로그 캣의 오류 :
03-23 10:13:19.706: E/Error(427): Error: java.lang.ClassNotFoundException: com.android.org.bouncycastle.jce.provider.JCERSAPrivateCrtKey
당신이 어떤 생각을 가지고 있습니까, 내가 어떻게이 안드로이드 2.2에서 작동 얻을 수 있을까?
[이미 질문하셨습니다] (http://stackoverflow.com/questions/15501592/problems-outsourcing-rsa-encryption-and-decryption). 새 질문을 게시하는 대신 원래 질문을 편집해야합니다. –
@DuncanJones 흠, 그 질문은 많은 정보를 남겨 둡니다. 답변이 없으므로 역으로하는 것이 좋습니다. 나는 이들 중 하나가 아마 다른 이슈가 아니라면 가야한다는 것에 동의한다 (그러나 나는 그런 생각을하지 않는다). –