1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Crypto: rename Cipher to CryptoManager.

This commit is contained in:
Tom Hacohen 2017-03-29 12:35:44 +01:00
parent abd13d4d3d
commit 1e6fc5a9cb
2 changed files with 8 additions and 8 deletions

View File

@ -75,14 +75,14 @@ abstract class BaseManager {
public String getContent(String keyBase64) {
// FIXME: probably cache encryption object
Crypto.Cipher cipher = new Crypto.Cipher(keyBase64, null);
return new String(cipher.decrypt(content), Charsets.UTF_8);
Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(keyBase64, null);
return new String(cryptoManager.decrypt(content), Charsets.UTF_8);
}
void setContent(String keyBase64, String content) {
// FIXME: probably cache encryption object
Crypto.Cipher cipher = new Crypto.Cipher(keyBase64, null);
this.content = cipher.encrypt(content.getBytes(Charsets.UTF_8));
Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(keyBase64, null);
this.content = cryptoManager.encrypt(content.getBytes(Charsets.UTF_8));
}
byte[] calculateHmac(String keyBase64, String uuid) {
@ -100,8 +100,8 @@ abstract class BaseManager {
}
// FIXME: probably cache encryption object
Crypto.Cipher cipher = new Crypto.Cipher(keyBase64, null);
return cipher.hmac(hashContent.toByteArray());
Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(keyBase64, null);
return cryptoManager.hmac(hashContent.toByteArray());
}
protected Base() {

View File

@ -31,12 +31,12 @@ public class Crypto {
return Base64.encodeToString(SCrypt.generate(password.getBytes(Charsets.UTF_8), salt.getBytes(Charsets.UTF_8), 16384, 8, 1, keySize), Base64.NO_WRAP);
}
static class Cipher {
static class CryptoManager {
private SecureRandom _random = null;
private final byte[] cipherKey;
private final byte[] hmacKey;
Cipher(String keyBase64, String salt) {
CryptoManager(String keyBase64, String salt) {
byte[] derivedKey; // FIXME use salt = hmac256(salt.getBytes(Charsets.UTF_8), Base64.decode(keyBase64, Base64.NO_WRAP));
derivedKey = Base64.decode(keyBase64, Base64.NO_WRAP);
cipherKey = hmac256("aes".getBytes(Charsets.UTF_8), derivedKey);