-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1600 from bitmark-inc/encrypt_env_secret
fix: encript env, decrypt when app run
- Loading branch information
Showing
14 changed files
with
254 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FERAL_FILE_SECRET_KEY_TESTNET= | ||
FERAL_FILE_SECRET_KEY_MAINNET= | ||
CHAT_SERVER_HMAC_KEY= | ||
AU_CLAIM_SECRET_KEY= | ||
MIXPANEL_KEY= | ||
METRIC_SECRET_KEY= | ||
BRANCH_KEY= | ||
SENTRY_DSN= | ||
ONESIGNAL_APP_ID= | ||
METRIC_ENDPOINT= | ||
WEB3_RPC_MAINNET_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
late dynamic cachedSecretEnv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'dart:convert'; | ||
import 'dart:math'; | ||
import 'package:cryptography/cryptography.dart'; | ||
|
||
// Example function for encryption | ||
Future<List<dynamic>> _encryptText(String text, String key) async { | ||
final algorithm = Chacha20.poly1305Aead(); | ||
final bytes = utf8.encode(key); | ||
final secretKey = await algorithm.newSecretKeyFromBytes(bytes); | ||
final secretBox = await algorithm.encryptString(text, secretKey: secretKey); | ||
final encryptText = secretBox.concatenation(); | ||
return [ | ||
base64Encode(encryptText), | ||
secretBox.nonce.length, | ||
secretBox.mac.bytes.length | ||
]; | ||
} | ||
|
||
String _generateKeyFromEntropy(String entropy, int length) { | ||
final random = Random(entropy.hashCode); // Use entropy's hash code as seed | ||
final entropyLength = entropy.length; | ||
return String.fromCharCodes(Iterable.generate( | ||
length, (_) => entropy.codeUnitAt(random.nextInt(entropyLength)))); | ||
} | ||
|
||
void main(List<String> arguments) async { | ||
if (arguments.length < 2) { | ||
print('Usage: dart encrypt.dart <text_to_encrypt> <entropy>'); | ||
return; | ||
} | ||
|
||
String textToEncrypt = arguments[0]; | ||
String entropy = arguments[1]; | ||
|
||
final encryptedText = | ||
await _encryptText(textToEncrypt, _generateKeyFromEntropy(entropy, 32)); | ||
print(encryptedText.join(' ')); | ||
} |
Oops, something went wrong.