diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-10-05 18:35:16 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-10-05 18:35:16 +0200 |
commit | bef6977aade3a901ac17ed1e31de22c8de066921 (patch) | |
tree | acf212a4fdf11391a2e380fd2795fd9573b48df4 /OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure | |
parent | c75c00f935faf02e65c1a6cb165ea6cf6b236432 (diff) | |
download | open-keychain-bef6977aade3a901ac17ed1e31de22c8de066921.tar.gz open-keychain-bef6977aade3a901ac17ed1e31de22c8de066921.tar.bz2 open-keychain-bef6977aade3a901ac17ed1e31de22c8de066921.zip |
New API version, import from clipboard
Diffstat (limited to 'OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure')
2 files changed, 85 insertions, 20 deletions
diff --git a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/Constants.java b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/Constants.java index dc54fc9e7..03e76254c 100644 --- a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/Constants.java +++ b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/Constants.java @@ -20,6 +20,6 @@ public final class Constants { public static final boolean DEBUG = BuildConfig.DEBUG; - public static final String TAG = "Keychain API"; + public static final String TAG = "Keychain"; } diff --git a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java index 8f56c124a..4a96de5a1 100644 --- a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java +++ b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java @@ -19,6 +19,8 @@ package org.sufficientlysecure.keychain.demo; import java.util.ArrayList; import java.util.List; +import org.openintents.openpgp.IOpenPgpKeyIdsCallback; +import org.openintents.openpgp.OpenPgpData; import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpServiceConnection; import org.openintents.openpgp.OpenPgpSignatureResult; @@ -66,12 +68,75 @@ public class OpenPgpProviderActivity extends Activity { } /** - * Callback from remote crypto service + * Callback from remote openpgp service */ + final IOpenPgpKeyIdsCallback.Stub getKeysEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() { + + @Override + public void onSuccess(final long[] keyIds) throws RemoteException { + Log.d(Constants.TAG, "getKeysEncryptCallback keyId " + keyIds[0]); + mActivity.runOnUiThread(new Runnable() { + + @Override + public void run() { + // encrypt after getting key ids + String inputStr = mMessage.getText().toString(); + OpenPgpData input = new OpenPgpData(inputStr); + + Log.d(Constants.TAG, "getKeysEncryptCallback inputStr " + inputStr); + + try { + mCryptoServiceConnection.getService().encrypt(input, + new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + }); + } + + @Override + public void onError(OpenPgpError error) throws RemoteException { + handleError(error); + } + + }; + + final IOpenPgpKeyIdsCallback.Stub getKeysSignAndEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() { + + @Override + public void onSuccess(final long[] keyIds) throws RemoteException { + Log.d(Constants.TAG, "getKeysSignAndEncryptCallback keyId " + keyIds[0]); + + mActivity.runOnUiThread(new Runnable() { + + @Override + public void run() { + // encrypt after getting key ids + String inputStr = mMessage.getText().toString(); + OpenPgpData input = new OpenPgpData(inputStr); + + try { + mCryptoServiceConnection.getService().signAndEncrypt(input, + new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + }); + } + + @Override + public void onError(OpenPgpError error) throws RemoteException { + handleError(error); + } + + }; + final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() { @Override - public void onSuccess(final byte[] outputBytes, OpenPgpSignatureResult signatureResult) + public void onSuccess(final OpenPgpData output, OpenPgpSignatureResult signatureResult) throws RemoteException { Log.d(Constants.TAG, "encryptCallback"); @@ -79,7 +144,7 @@ public class OpenPgpProviderActivity extends Activity { @Override public void run() { - mCiphertext.setText(new String(outputBytes)); + mCiphertext.setText(output.getString()); } }); } @@ -94,7 +159,7 @@ public class OpenPgpProviderActivity extends Activity { final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() { @Override - public void onSuccess(final byte[] outputBytes, final OpenPgpSignatureResult signatureResult) + public void onSuccess(final OpenPgpData output, final OpenPgpSignatureResult signatureResult) throws RemoteException { Log.d(Constants.TAG, "decryptAndVerifyCallback"); @@ -102,7 +167,7 @@ public class OpenPgpProviderActivity extends Activity { @Override public void run() { - mMessage.setText(new String(outputBytes)); + mMessage.setText(output.getString()); if (signatureResult != null) { Toast.makeText(OpenPgpProviderActivity.this, "signature result:\n" + signatureResult.toString(), @@ -135,43 +200,43 @@ public class OpenPgpProviderActivity extends Activity { } public void encryptOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); - try { - mCryptoServiceConnection.getService().encrypt(inputBytes, - mEncryptUserIds.getText().toString().split(","), true, encryptCallback); + mCryptoServiceConnection.getService().getKeyIds( + mEncryptUserIds.getText().toString().split(","), true, getKeysEncryptCallback); } catch (RemoteException e) { Log.e(Constants.TAG, "CryptoProviderDemo", e); } } public void signOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); + String inputStr = mMessage.getText().toString(); + OpenPgpData input = new OpenPgpData(inputStr); try { - mCryptoServiceConnection.getService().sign(inputBytes, true, encryptCallback); + mCryptoServiceConnection.getService().sign(input, + new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback); } catch (RemoteException e) { Log.e(Constants.TAG, "CryptoProviderDemo", e); } } - public void encryptAndSignOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); - + public void signAndEncryptOnClick(View view) { try { - mCryptoServiceConnection.getService().signAndEncrypt(inputBytes, - mEncryptUserIds.getText().toString().split(","), true, encryptCallback); + mCryptoServiceConnection.getService().getKeyIds( + mEncryptUserIds.getText().toString().split(","), true, + getKeysSignAndEncryptCallback); } catch (RemoteException e) { Log.e(Constants.TAG, "CryptoProviderDemo", e); } } public void decryptAndVerifyOnClick(View view) { - byte[] inputBytes = mCiphertext.getText().toString().getBytes(); + String inputStr = mCiphertext.getText().toString(); + OpenPgpData input = new OpenPgpData(inputStr); try { - mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, - decryptAndVerifyCallback); + mCryptoServiceConnection.getService().decryptAndVerify(input, + new OpenPgpData(OpenPgpData.TYPE_STRING), decryptAndVerifyCallback); } catch (RemoteException e) { Log.e(Constants.TAG, "CryptoProviderDemo", e); } |