SD 카드에 저장된 내 앱의 xml 파일을 암호화/해독하려고합니다. using this code. 암호화가 잘 작동하는 동안, 내가 붙어있는 암호 해독 부분입니다.SD 카드 안드로이드에서 XML 파일 암호 해독
암호화 코드 :
private void writeToFile(final String xmlString, final String exportFileName) throws IOException {
File dir = new File(Environment.getExternalStorageDirectory(), BData.DATASUBDIRECTORY);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, exportFileName);
file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
try {
String fileData = AdvancedCrypto.encrypt("myPassword", "mySalt"), xmlString.toString());
bos.write(fileData.getBytes());
} catch (Exception e){
} finally {
if (bos != null) {
bos.flush();
bos.close();
}
}
}
암호 해독 코드 : 해독 방법이 라인에서
07-07 21:44:27.755: W/System.err(5608): Caused by: java.lang.StringIndexOutOfBoundsException: length=11; regionStart=0; regionLength=32
07-07 21:44:27.755: W/System.err(5608): at java.lang.String.startEndAndLength(String.java:593)
07-07 21:44:27.755: W/System.err(5608): at java.lang.String.substring(String.java:1474)
: :이 오류를 던지고
public void getDataFromXML(Context context, String fileName){
try
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser _xml = factory.newPullParser();
// get a reference to the file.
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + fileName);
// create an input stream to be read by the stream reader.
FileInputStream fis = new FileInputStream(file);
BufferedInputStream buf = new BufferedInputStream(fis);
int size = (int) file.length();
byte[] contents = new byte[size];
//byte[] data = buf.read(contents);
String fileData = AdvancedCrypto.decrypt("myPassword", "mySalt"), contents.toString());
buf.read(fileData.getBytes());
// set the input for the parser using an InputStreamReader
_xml.setInput(buf, HTTP.UTF_8);
buf.close();
int eventType = _xml.getEventType();
boolean done = false;
//..rest of the code
}
}
String ivHex = encrypted.substring(0, IV_LENGTH * 2);
파일을 올바르게 읽는 중입니까?
나는이 코드를 quesiton에 링크했다 : http://pocket-for-android.1047292.n5.nabble.com/Encryption-method-and-reading-the-Dropbox-backup-td4344194.html#a4454327 – input
정말로, 나쁘다. 내 편집을 참조하십시오. – ntoskrnl