> For the complete documentation index, see [llms.txt](https://developer.aliothx.net/start/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.aliothx.net/start/security/index/en-decoding.md).

# 암/복호화

## ![](/files/kVVDmuZUV6tIYNEijhbm)

## 대칭키(AES) 암호화&#x20;

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

```dart
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)를 생성하고, 이를 사용하여 평문을 암호화하고 복호화합니다.

#### 결과

![](/files/Zx9wczYSVKaGzfpMaDDC)

\
비대칭키(RSA) 암호화
-------------

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

```dart
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 암호화를 위해 공개 키와 개인 키를 사용하고, 이를 사용하여 평문을 암호화하고 복호화합니다.

#### 결과

![](/files/7AoDRuKxXAGWQphacXsv)
