Browse Source

Remove redundant base64 encoding

Vishnu Mohandas 4 years ago
parent
commit
cde0eccc60
1 changed files with 10 additions and 13 deletions
  1. 10 13
      lib/core/configuration.dart

+ 10 - 13
lib/core/configuration.dart

@@ -1,4 +1,3 @@
-import 'dart:convert';
 import 'dart:io' as io;
 import 'dart:io' as io;
 
 
 import 'package:flutter_secure_storage/flutter_secure_storage.dart';
 import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@@ -45,12 +44,11 @@ class Configuration {
   Future<KeyAttributes> generateAndSaveKey(String passphrase) async {
   Future<KeyAttributes> generateAndSaveKey(String passphrase) async {
     final key = CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
     final key = CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
     final kekSalt = CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
     final kekSalt = CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
-    final kek =
-        base64.encode(CryptoUtil.scrypt(passphrase, kekSalt, 32).codeUnits);
+    final kek = CryptoUtil.scrypt(passphrase, kekSalt, 32);
     final kekHashSalt =
     final kekHashSalt =
         CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
         CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
     final kekHash = CryptoUtil.scrypt(kek, kekHashSalt, 32);
     final kekHash = CryptoUtil.scrypt(kek, kekHashSalt, 32);
-    final iv = CryptoUtil.getBase64EncodedSecureRandomString(length: 32);
+    final iv = CryptoUtil.getBase64EncodedSecureRandomString(length: 16);
     final encryptedKey = CryptoUtil.encryptToBase64(key, kek, iv);
     final encryptedKey = CryptoUtil.encryptToBase64(key, kek, iv);
     final attributes =
     final attributes =
         KeyAttributes(kekSalt, kekHash, kekHashSalt, encryptedKey, iv);
         KeyAttributes(kekSalt, kekHash, kekHashSalt, encryptedKey, iv);
@@ -61,8 +59,7 @@ class Configuration {
 
 
   Future<void> decryptAndSaveKey(
   Future<void> decryptAndSaveKey(
       String passphrase, KeyAttributes attributes) async {
       String passphrase, KeyAttributes attributes) async {
-    final kek = base64.encode(
-        CryptoUtil.scrypt(passphrase, attributes.kekSalt, 32).codeUnits);
+    final kek = CryptoUtil.scrypt(passphrase, attributes.kekSalt, 32);
     bool correctPassphrase =
     bool correctPassphrase =
         CryptoUtil.compareHash(kek, attributes.kekHash, attributes.kekHashSalt);
         CryptoUtil.compareHash(kek, attributes.kekHash, attributes.kekHashSalt);
     if (!correctPassphrase) {
     if (!correctPassphrase) {
@@ -74,17 +71,17 @@ class Configuration {
   }
   }
 
 
   String getEndpoint() {
   String getEndpoint() {
-    return "192.168.0.106";
+    return "192.168.0.100";
   }
   }
 
 
   String getHttpEndpoint() {
   String getHttpEndpoint() {
     if (getEndpoint() == null) {
     if (getEndpoint() == null) {
       return "";
       return "";
     }
     }
-    return "http://" + getEndpoint() + ":8080";
+    return "http://" + getEndpoint();
   }
   }
 
 
-  void setEndpoint(String endpoint) async {
+  Future<void> setEndpoint(String endpoint) async {
     await _preferences.setString(endpointKey, endpoint);
     await _preferences.setString(endpointKey, endpoint);
   }
   }
 
 
@@ -92,7 +89,7 @@ class Configuration {
     return _preferences.getString(tokenKey);
     return _preferences.getString(tokenKey);
   }
   }
 
 
-  void setToken(String token) async {
+  Future<void> setToken(String token) async {
     await _preferences.setString(tokenKey, token);
     await _preferences.setString(tokenKey, token);
   }
   }
 
 
@@ -100,7 +97,7 @@ class Configuration {
     return _preferences.getString(emailKey);
     return _preferences.getString(emailKey);
   }
   }
 
 
-  void setEmail(String email) async {
+  Future<void> setEmail(String email) async {
     await _preferences.setString(emailKey, email);
     await _preferences.setString(emailKey, email);
   }
   }
 
 
@@ -108,11 +105,11 @@ class Configuration {
     return _preferences.getInt(userIDKey);
     return _preferences.getInt(userIDKey);
   }
   }
 
 
-  void setUserID(int userID) async {
+  Future<void> setUserID(int userID) async {
     await _preferences.setInt(userIDKey, userID);
     await _preferences.setInt(userIDKey, userID);
   }
   }
 
 
-  void setOptInForE2E(bool hasOptedForE2E) async {
+  Future<void> setOptInForE2E(bool hasOptedForE2E) async {
     await _preferences.setBool(hasOptedForE2EKey, hasOptedForE2E);
     await _preferences.setBool(hasOptedForE2EKey, hasOptedForE2E);
   }
   }