toEncrypt static method

Future<String> toEncrypt(
  1. String jsonString
)

Implementation

static Future<String> toEncrypt(String jsonString) async {
  _print(jsonString);

  int offset = int.parse(randomNumeric(2));
  offset = (offset % 2) == 0 ? offset : offset + 1; // 항상 짝수로 만듬

  final String encryptionKey = randomAlphaNumeric(32);
  final String offsetString1 = randomAlphaNumeric(offset);
  final String offsetString2 = randomAlphaNumeric(offset);
  encrypt.Key key = encrypt.Key.fromUtf8(encryptionKey);
  encrypt.IV iv = encrypt.IV.fromLength(16);
  final encryptor = encrypt.Encrypter(encrypt.AES(key));
  final cypherText = encryptor.encrypt(jsonString, iv: iv).base64;

  int fakeOffset = (offset / 2).round() + 16;

  String ivText = iv.base64;
  int ivTextLength = ivText.length;

  _print('offset=$offset');
  _print('ivTextLength=$ivTextLength');
  _print('ivText=$ivText');
  _print('fakeoffset=$fakeOffset');
  _print('offsetString1=$offsetString1');
  _print('key=$encryptionKey');
  _print('text=$cypherText');
  _print('offsetString2=$offsetString2');

  String retval =
      '{"encryptVersion":"$encryptVersion","encrypted":"$ivTextLength$ivText$fakeOffset$offsetString1$encryptionKey$cypherText$offsetString2"}';
  _print(retval);
  return retval;
}