mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Add first basic implementation of Apgservice
Provides an AIDL-API for other apps to encrypt and decrypt a string symmetrically with a passphrase. Function names and API is by no way finalized and will change! Support for asymetric encription will follow. For reference and discussion see issue #71, https://code.google.com/p/android-privacy-guard/issues/detail?id=71
This commit is contained in:
parent
fc08f14ef1
commit
e8d29c01c2
@ -195,7 +195,11 @@
|
|||||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
||||||
|
|
||||||
<service android:name=".Service" />
|
<service android:name=".Service" />
|
||||||
|
<service android:name=".ApgService" android:enabled="true" android:exported="true" android:process=":remote" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.thialfihar.android.apg.IApgService"/>
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
<provider
|
<provider
|
||||||
android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"
|
android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"
|
||||||
android:name="org.thialfihar.android.apg.provider.DataProvider"
|
android:name="org.thialfihar.android.apg.provider.DataProvider"
|
||||||
|
76
src/org/thialfihar/android/apg/ApgService.java
Normal file
76
src/org/thialfihar/android/apg/ApgService.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class ApgService extends Service {
|
||||||
|
static String TAG = "ApgService";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
Log.d(TAG, "bound");
|
||||||
|
return mBinder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final IApgService.Stub mBinder = new IApgService.Stub() {
|
||||||
|
|
||||||
|
public String encrypt_with_passphrase(String msg, String passphrase) {
|
||||||
|
Preferences mPreferences = Preferences
|
||||||
|
.getPreferences(getApplicationContext());
|
||||||
|
InputStream inStream = new ByteArrayInputStream(msg.getBytes());
|
||||||
|
InputData in = new InputData(inStream, 9999);
|
||||||
|
OutputStream out = new ByteArrayOutputStream();
|
||||||
|
long enc_keys[] = {};
|
||||||
|
|
||||||
|
Apg.initialize(getApplicationContext());
|
||||||
|
try {
|
||||||
|
Apg.encrypt(
|
||||||
|
getApplicationContext(),
|
||||||
|
in,
|
||||||
|
out,
|
||||||
|
true, // armored
|
||||||
|
enc_keys, // encryption keys
|
||||||
|
0, // signature key
|
||||||
|
null, // signature passphrase
|
||||||
|
null, // progress
|
||||||
|
mPreferences.getDefaultEncryptionAlgorithm(),
|
||||||
|
mPreferences.getDefaultHashAlgorithm(),
|
||||||
|
Id.choice.compression.none, false, // mPreferences.getForceV3Signatures(),
|
||||||
|
passphrase // passPhrase
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, "Exception in encrypt");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Encrypted");
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decrypt_with_passphrase(String encrypted_msg,
|
||||||
|
String passphrase) {
|
||||||
|
InputStream inStream = new ByteArrayInputStream(encrypted_msg
|
||||||
|
.getBytes());
|
||||||
|
InputData in = new InputData(inStream, 9999); // XXX what size in
|
||||||
|
// second parameter?
|
||||||
|
OutputStream out = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
Apg.decrypt(getApplicationContext(), in, out, passphrase, null, // progress
|
||||||
|
true // symmetric
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, "Exception in decrypt");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
6
src/org/thialfihar/android/apg/IApgService.aidl
Normal file
6
src/org/thialfihar/android/apg/IApgService.aidl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
interface IApgService {
|
||||||
|
String encrypt_with_passphrase(String msg, String passphrase);
|
||||||
|
String decrypt_with_passphrase(String encrypted_msg, String passphrase);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user