no functional change

edited some crypto functions
This commit is contained in:
Vishal 2022-12-26 16:06:50 +05:30
parent 9abe554bd5
commit 43b7e285ef

View File

@ -1502,8 +1502,7 @@ Uint8List myPrivateDecryptRaw( String privateString,
String publicString,
Uint8List cipherText,
[String b64IV = ""]) {
try {
try {
List<List<int>> byteSecret = [];
if( gMapByteSecret.containsKey(publicString)) {
byteSecret = gMapByteSecret[publicString]??[];
@ -1515,25 +1514,20 @@ try {
}
final secretIV = byteSecret;
final key = Uint8List.fromList(secretIV[0]);
final iv = b64IV.length > 6
? 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?>);
final Uint8List finalPlainText = Uint8List(cipherText.length); // allocate space
var offset = 0;
@ -1544,13 +1538,13 @@ try {
//remove padding
offset += cipherImpl.doFinal(cipherText, offset, finalPlainText, offset);
return finalPlainText.sublist(0, offset);
} catch(e) {
} catch(e) {
if( gDebug >= 0) print("Decryption error = $e");
return Uint8List(0);
}
}
}
/// Encrypt data using self private key in nostr format ( with trailing ?iv=)
// Encrypt data using self private key in nostr format ( with trailing ?iv=)
String myEncrypt( String privateString,
String publicString,
String plainText) {
@ -1570,7 +1564,7 @@ String myEncryptRaw( String privateString,
final _sGen = Random.secure();;
fr.seed(KeyParameter(
Uint8List.fromList(List.generate(32, (_) => _sGen.nextInt(255)))));
final iv = fr.nextBytes(16); //Uint8List.fromList(secretIV[1]);
final iv = fr.nextBytes(16);
CipherParameters params = new PaddedBlockCipherParameters(
new ParametersWithIV(new KeyParameter(key), iv), null);
@ -1582,7 +1576,8 @@ String myEncryptRaw( String privateString,
params as PaddedBlockCipherParameters<CipherParameters?,
CipherParameters?>);
final Uint8List outputEncodedText = Uint8List(uintInputText.length + 16); // allocate space
// allocate space
final Uint8List outputEncodedText = Uint8List(uintInputText.length + 16);
var offset = 0;
while (offset < uintInputText.length - 16) {