made map out of bytesecret and do look up second time

speeds up a lot . each takes 0.05 secs to calculate.
This commit is contained in:
Vishal
2022-09-07 03:53:15 +05:30
parent 11972d5328
commit 9558197cac
4 changed files with 36 additions and 6 deletions

View File

@@ -200,6 +200,7 @@ class EventData {
break;
case 4:
if( userPrivateKey == ""){ // cant process if private key not given
break;
}
@@ -919,17 +920,32 @@ String myPrivateDecrypt( String privateString,
String publicString,
String b64encoded,
[String b64IV = ""]) {
Uint8List encdData = convert.base64.decode(b64encoded);
final rawData = myPrivateDecryptRaw(privateString, publicString, encdData, b64IV);
return convert.Utf8Decoder().convert(rawData.toList());
}
Map<String, List<List<int>>> gMapByteSecret = {};
Uint8List myPrivateDecryptRaw( String privateString,
String publicString,
Uint8List cipherText,
[String b64IV = ""]) {
try {
final secretIV = Kepler.byteSecret(privateString, publicString);
List<List<int>> byteSecret = [];
if( gMapByteSecret.containsKey(publicString)) {
byteSecret = gMapByteSecret[publicString]??[];
}
if( byteSecret.isEmpty) {
byteSecret = Kepler.byteSecret(privateString, publicString);;
gMapByteSecret[publicString] = byteSecret;
}
final secretIV = byteSecret;
final key = Uint8List.fromList(secretIV[0]);
@@ -937,12 +953,14 @@ try {
? convert.base64.decode(b64IV)
: Uint8List.fromList(secretIV[1]);
CipherParameters params = new PaddedBlockCipherParameters(
new ParametersWithIV(new KeyParameter(key), iv), null);
PaddedBlockCipherImpl cipherImpl = new PaddedBlockCipherImpl(
new PKCS7Padding(), new CBCBlockCipher(new AESEngine()));
cipherImpl.init(false,
params as PaddedBlockCipherParameters<CipherParameters?,
CipherParameters?>);
@@ -957,7 +975,6 @@ try {
//remove padding
offset += cipherImpl.doFinal(cipherText, offset, finalPlainText, offset);
assert(offset == cipherText.length);
return finalPlainText.sublist(0, offset);
} catch(e) {
//print("cannot open file $gEventsFilename");