Comments (11)
Thanks for the feedback. I'll update it by tomorrow.
from conceal.
Were you looking for specific examples to do some particular thing?
from conceal.
a sample app would be great. in my case it would be helpful to know how to get the keychain associated with particular encrypted data (for say, sharing stuff over bluetooth streams securely). thanks for the response
from conceal.
I think I understand what you mean. In short, the keychain system currently does not have a discovery service for the key for an id, however you can always create a custom keychain manager which is id aware:
Obviously this is not complete but it really also depends on how your application stores data
class KeychainManager {
Map<String, KeyChain> mKeychains = new HashMap<String, KeyChain>();
SharedPreferences mSharedPreferences;
public KeyChain getKeyChainForId(String id) {
if (!mKeychains.containsKey(id)) {
mKeychains.put(id, new SimpleKeyChain(id));
maybeRecordId(id);
}
return mKeychains.get(id);
}
private maybeRecordId(String id) {
// record id in persistent store if present
Set<String> ids = mSharedpreferences.getStringSet(KEYCHAIN_KEY);
if (ids == null) {
ids = new HashSet<String>();
}
ids.add(id);
mSharedPreferences.edit().putStringSet(ids).commit();
}
void destoryAllKeys() {
Set<String> ids = mSharedpreferences.getStringSet(KEYCHAIN_KEY);
if (ids == null) {
return;
}
for (String id : ids) {
new SimpleKeyChain(id).destroyKeys();
}
}
}
class SimpleKeyChain implements KeyChain {
String mId;
SharedPreferences mSharedPreferences;
final String KEYPREFIX = "KEY";
public void SimpleKeyChain(String id) {
mId = id;
}
public synchronized byte[] getCipherKey() throws KeyChainException {
String prefKey = KEYPREFIX + mId;
String key = mSharedPreferences.getString(prefKey, null);
byte[] keyBytes = null;
if (key == null) {
byte[] keyBytes = maybeGenerateKey(); // from the SharedPreferencesKeyChain
mSharedPreferences.edit().put(prefKey, key).commit();
} else {
keyBytes = key.getBytes();
}
return keyBytes;
}
void destroyKeys() {
// similar to SharedPrefsBackedKeyChain
}
....
}
How does this sound. Did I understand your question correctly?
Ultimately we need to provide a Key management API which might be useful to you, until then you could possibly work around it with your custom key api and it shouldn't be too hard to implement.
from conceal.
hi again, i ended up with something similar. thanks for this.
also, would it be possible to decrypt the content directly from the bluetooth inputstream or would you advise creating a new stream for decryption?
from conceal.
That's great. I think key management might be a useful feature in conceal.
I think you could just wrap the bluetooth input stream in the crypto stream for decryption
first create the crypto object using your particular keychain and then use:
InputStream wrappedStream = crypto.getCipherInputStream(bluetoothStream, entity);
from conceal.
i tried what you suggested, using the sample bluetooth chat app (https://android.googlesource.com/platform/development/+/eclair-passion-release/samples/BluetoothChat) and changing the ConnectedThread constructor like this:
public ConnectedThread(BluetoothSocket socket, String socketType) {
Log.d(TAG, "create ConnectedThread: " + socketType);
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
InputStream cryptIn = null;
OutputStream cryptOut = null;
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
>> cryptIn = crypto.getCipherInputStream(tmpIn,entity); << gets stuck on this line
cryptOut = crypto.getCipherOutputStream(tmpOut,entity);
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e);
}
catch (CryptoInitializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyChainException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mmInStream = cryptIn;
mmOutStream = cryptOut;
}
it gets stuck on that line, but without returning any kind of error or stack trace. also i'm passing the keychain name between the devices via beam before calling ConnectedThread.
from conceal.
The way that socket streams work is that they block until data is available to read. Are you sure you're flushing data from the other side.
from conceal.
since the messages i'm sending between the devices are pretty short, i'm looking into using the encrypt/decrypt methods instead.
is it sufficient to pass the cipherkey and the entity name between the devices to have device B decrypt a message from device A?
from conceal.
It would be sufficient to pass the keys between the devices, and then initialize a KeyChain using that key, but you have to probably consider how you are going to get the keys between devices without someone sniffing them.
Another suggestion is that you might want to use 2 different keys for each direction of communication
from conceal.
using the byte[] methods encrypt and decrypt worked out for me, now i just need to make sure that swapping keys over Beam isn't a terrible idea.
thanks for all the help!
from conceal.
Related Issues (20)
- Why not think about using the cpu feature like ANDROID_CPU_ARM64_FEATURE_AES?
- Native Crash!!! HOT 6
- [Question] Password based key derivation usage HOT 5
- native crash and app can't pickup the exception,Can this exception wrap with java exception,then i can catch it
- native crash on Samsung HOT 1
- README.md refers to deprecated crypto.getCipherOutputStream
- What do I need to know in order to encrypt elsewhere for Conceal to decrypt? HOT 3
- The speed of decrypting the file is twice faster than the speed of encrypting the same file
- How to save encrypted file to internal folder ?
- App crashed in native method
- Conflicts using in React Native project due to com.facebook.jni.DestructorThread HOT 3
- showing NoSuchMethodException on Android P when initialing the SoLoader HOT 10
- Incompatibility with the Facebook library Flipper
- Conflict with React Native in v2.0.2 HOT 6
- Subpar PBKDF2 performance
- PHP Implementation HOT 1
- signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) Native Crash in Google Play Console HOT 5
- App crashes when running as 64 bit version: `libfb.so is 64-bit instead of 32-bit` HOT 1
- Fatal signal 11 (SIGSEGV), code 2 upon file decryption.
- Native crash (conceal version 2.0.2) java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libfb.so HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conceal.