Page cover image

암/복호화

대칭키(AES) 암호화

AES (Advanced Encryption Standard)는 대칭키 암호화 알고리즘으로, 동일한 키를 사용하여 데이터를 암호화 및 복호화합니다.

final key = encrypt.Key.fromSecureRandom(32);
final iv = encrypt.IV.fromSecureRandom(16);

final encrypter = encrypt.Encrypter(encrypt.AES(key));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);

위 코드는 Flutter에서 AES 암호화를 어떻게 수행하는지 보여줍니다. AES 암호화를 위해 암호화 키와 초기화 벡터(IV)를 생성하고, 이를 사용하여 평문을 암호화하고 복호화합니다.

결과

비대칭키(RSA) 암호화

RSA (Rivest–Shamir–Adleman)는 비대칭키 암호화 알고리즘으로, 공개키와 개인키를 사용하여 데이터를 암호화 및 복호화합니다.

final publicPem = await rootBundle.loadString('assets/pem/public.pem');
final publicKey = RSAKeyParser().parse(publicPem) as RSAPublicKey;

final privatePem = await rootBundle.loadString('assets/pem/private.pem');
final privKey = RSAKeyParser().parse(privatePem) as RSAPrivateKey;

final encrypter = encrypt.Encrypter(
    encrypt.RSA(publicKey: publicKey, privateKey: privKey));

final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt(encrypted);

위 코드는 Flutter에서 RSA 암호화를 어떻게 수행하는지 보여줍니다. RSA 암호화를 위해 공개 키와 개인 키를 사용하고, 이를 사용하여 평문을 암호화하고 복호화합니다.

결과

Last updated