대칭키, 비대칭키Symmetric and Asymmetric Keys
암호학의 기본! 대칭키와 비대칭키The basics of cryptography! Symmetric and asymmetric keys
정보보안의 3요소
기본적으로 암호를 이해하기 위해서는 통칭 ‘CIA’라고 하는 ‘정보보안의 3요소’를 알아야 합니다.
- 기밀성(Confidentiality) : 인가된 사용자만 아는 비밀스러운 정보.
- 무결성(Integrity) : 기존의 정보에서 변경되지 않은 정보, 또는 인가된 방법에 의해서 변경되는 정보.
- 가용성(Availability) : 인가된 사용자가 정보를 원할때 지장없이 이용을 보장.
암호의 목적은 데이터의 암호화를 통한 ‘기밀성’을 보장하는 것이며, 부가적으로 데이터 변경에 대한 보장을 해주는 ‘무결성’에 그 목적이 있습니다.
암호화와 복호화
‘암호의 목적은 데이터의 암호화’라고 했습니다. 그렇다면 암호화란 무엇일까요?

> 암호화와 복호화
‘암호화(Encryption)’란 일반적인 메시지를 뜻하는 평문(plaintext)을 암호화 알고리즘을 이용하여 코드화된 메시지로 만들어 이해할 수 없도록 암호문(ciphertext)으로 만드는 것을 의미합니다.
이와 반대로 ‘복호화(Decryption)’ 란 암호문을 다시 평문으로 만드는 것을 의미합니다.
암호의 분류
암호는 크게 ‘양방향 암호’와 ‘일방향 암호’로 구분 할 수 있습니다. 여기서 방향은 암호화와 복호화의 방향에 따른 분류입니다. 양방향은 암호화와 복호화가 모두 가능하며 일방향 암호는 암호화만을 가능한 것을 의미합니다.

> 대칭키와 비대칭키는 양방향 암호이다.
혼돈과 확산
모든 암호화에 사용되는 기초 기법은 크게 ‘혼돈’과 ‘확산’으로 나눌수 있습니다.

> Caesar 암호, Scytale 암호
혼돈(Confusion)
혼돈(Confusion)이란 평문의 문자들을 다른 문자, 숫자, 기호 또는 심벌로 바꾸는 것을 의미합니다. 대표적으로 Caesar 기법이 있습니다.
로마의 황제였던 줄리어스 시저가 사용한 이 방법은 A는 D로, B는 E로 바꿔 쓰고, 읽는 방식으로 문자를 문자 3개씩 앞뒤로 당겨서 읽으면 원래의 평문을 얻을 수 방법입니다.
확산(Diffusion)
확산(Diffusion)이란 글자의 위치를 변경하는 기법입니다. 대표적으로 Scytale 기법이 있습니다.
특정 지름을 갖는 막대에 종이를 감고 평문을 횡으로 쓴 다음 종이를 풀면 평문의 각 문자는 재배치되어 정보를 인식할 수 없게 됩니다. 이를 지름이 같은 막대에 다시 감으면 평문을 읽을 수 있는 방법입니다.
키의 관리
-
Caesar기법에서 문자 3개씩 이동한다는 약속 -
Scytale기법에서 사용한 막대의 지름
이것들은 해당 암호문를 다시 평문으로 만들기 위해 필요한 열쇠(Key) 입니다.
암호화에서 가장 중요한 핵심은 ‘강력한 알고리즘을 만드는것’이라 할 수 있습니다. 하지만 아무리 강력한 암호화 알고리즘이라 할지라도, 해당 암호화에 사용한 키값을 알고 있다면 이는 무용지물이겠죠.
따라서 암호화에 사용한 ‘키를 어떻게 안전하게 관리 할 것인가’ 또한 암호화의 핵심이라해도 무방합니다.
대칭키 암호화(Symmetric-key Cryptography)
일반적인 암호는 평문을 키값을 이용하여 암호화 하고, 암호문을 같은 키값을 이용하여 복호화가 가능한 ‘대칭키’를 의미합니다. 여기서 ‘대칭키’란 암호화와 복호화에 사용하는 키값이 같은 것을 의미합니다.

> 대칭키: 암호화에 사용한 검은색 키를 다시 사용해 복호화를 수행
일반적으로 암호에서 사용하는 용어로 ‘송신자 A’ = 엘리스(Alice) / ‘수신자 B’ = 밥(Bob)으로 지칭하겠습니다.
두 사람이 같은 키를 이용한 암호화 통신을 한다고 생각해봅시다. 엘리스는 키로 평문을 암호화하여 보내고, 밥은 동일한 키로 암호문을 복호화하여 안전하게 통신을 할 수 있습니다.
하지만 여기서 두 사람이 암호화 통신을 하기 위한 기본 전제 조건이 있습니다.
‘송신자와 수신자는 암호화 통신을 하기 위해서는 같은 키값을 공유하고 있어야 한다.’
문제는 여기서 발생합니다.
키의 공유

> 도청으로 Key 탈취의 위험 (키 배송 문제)
엘리스가 키를 밥에게 보내지 않으면 밥은 엘리스에게 암호문을 받아도 해당 암호문을 평문으로 복호화 할 수 없습니다. 하지만 키를 보내려해도 이를 노린 해커가 키를 탈취해 암호문을 복호화 할 수도 있습니다.
이러한 문제점은 암호의 가장 중요한 ‘기밀성’에 치명적입니다. “키를 공유 해야하는데 키를 보내지도 못한다.” 이것을 ‘키 배송 문제(key distribution problem)’라 합니다.
그렇다고 모든 통신채널을 100% 안전하게 만들 수도 없습니다. 그렇다면 어떻게 키값을 ‘불안정한(insecure) 통신채널’을 이용해서 안전하게 공유 할수 있을까요?
비대칭키 암호화 (Asymmetric-key Cryptography)
‘키 배송 문제’를 해결하는 방법에는 몇가지 방법이 있습니다. 그 중에서 가장 대표적인 방법이 ‘비대칭키 암호화’ 방식입니다.
암호화에 사용하는 키 따로, 복호화에 사용하는 키 따로 존재하는 방식 입니다. 암호화/복호화에 사용하는 키가 다르기 때문에 ‘비대칭키’라고 합니다. 두 개의 키는 아래와 같습니다.
- ‘누구나 볼수 있는 키’ = ‘공개키(public-key)’
- ‘본인만 갖고 있는 키’ = ‘개인키(private-key)’
한가지 더 기억해야 하는 중요한 내용이 있습니다. 개인키 또는 공개키로 암호화한 내용은 나머지 다른 키로만 복호화 가능합니다.
- 공개키로 암호화한 내용은 오직 개인키로만 복호화 가능
- 개인키로 암호화한 내용은 오직 공개키로만 복호화 가능
즉 두 가지 키 모두 암호화/복호화에 사용 가능하며, 반대쪽 키로만 암호화/복호화가 가능합니다.

> 비대칭키 : 두 개의 키를 사용하여 암호화와 복호화를 하는 방법
기본적인 흐름은 다음과 같습니다.
- 엘리스는 평문을 ‘암호화’하기 위해서 ‘밥의 공개키(public-key)’를 사용.
- 밥은 수신한 암호문을 ‘밥의 개인키(private-key)’를 이용하여 ‘복호화’.
여기서 나온 공개키라는 개념때문에 ‘공개키 암호화(public-key cryptography)’ 방식이라고 부르기도 합니다.
대칭키와 비대칭키의 쓰임
그렇다면 우리가 사용하는 암호화는 전부 비대칭키만 쓸까요? 반은 맞고 반은 틀렸습니다.
비대칭키는 복잡한 연산인 ‘소인수 분해’를 기반해서 동작합니다. 때문에 많은 양의 데이터를 암호화 하기에는 적절하지 않습니다. 반면, 대칭키는 암호화와 복호화 속도가 훨씬 빠릅니다.
“엥? 그럼 데이터 암호화에 안쓰면 뭐에 쓴다는겨?”
물론 비대칭키만 쓰이는 경우도 많이 있습니다. 데이터 암호화가 목적이 아니라면 충분히 좋은 방법이고 이미 많은 기술에서 쓰이고 있습니다. 대표적인 경우가 ‘전자서명’ 입니다. 데이터를 암호화하는 것이 목적이 아니라 무결성(변조 여부) 검증이 주 목적 입니다.
대칭키를 위한 비대칭키의 쓰임
대칭키와 비대칭키의 장단점을 다시 한번 정리해봅시다.
| 장점 | 단점 | |
|---|---|---|
| 대칭키 | 빠르고 효율적 | 키 공유가 어려움 |
| 비대칭키 | 안전한 키 공유 | 연산 비용이 높음 |
이놈도 저놈도 사용하려니 뭔가 부족해 보입니다. 그래서 실제로는 두 방식을 혼합해서 사용하는 경우가 많습니다.
예시 : GitHub SSH 설정
GitHub에 SSH 설정하는 과정을 한번 생각해 봅시다. 사용자가 직접 비대칭키를 만들어서 개인키는 보관하고, 공개키를 GitHub에 등록 합니다.
- GitHub 서버에는 공개키(public-key)
- 사용자만 가지고 있는 개인키(private-key)

> 사용자가 GitHub에 등록한 공개키는 누구나 확인 가능하다
초기 연결 설정 (비대칭키 사용)
- 사용자는 비대칭키를 생성하여 개인키는 보관하고 GitHub에 공개키를 등록
- 사용자와 Github는 SSH에서 사용할 동일한 대칭키(세션 키)를 생성 (Diffie-Hellman 키 교환)
- 사용자는 개인키로 서명을 만들어 GitHub 서버에 전송
- GitHub 서버는 공개키로 서명을 복호화하여 검증

> 대칭키를 비대칭키로 암호화해서 안전하게 배송한다.
만약 GitHub에 등록된 공개키의 짝인 개인키가 아니면 사용자는 인증에 실패하게 됩니다. 올바른 개인키를 가진 사람만 인증을 통과 할 수 있겠죠?
이후 통신 (대칭키 사용)
양쪽 모두 동일한 세션 키를 공유하게 되었으므로, 이후의 모든 통신은 이 대칭키를 사용하여 안전하게 데이터를 암호화/복호화 할 수 있게 됩니다. 이런 방식은 SSH뿐만 아니라 HTTPS 등 많은 보안 프로토콜에서 사용되는 일반적인 패턴입니다.

마무리
여기까지 대칭키와 비대칭키에 대해서 알아봤습니다. 정리 하겠습니다. 😊
- 대칭키는 ‘키 배송 문제(key distribution problem)’가 있다.
- 비대칭키는 데이터 암호화에는 부적합하다.
- 두 방식의 장점을 결합하여 서로의 단점을 보완하여 사용
참고 문헌
아래의 영상에서 공개키의 기본 원리와 ‘소인수 분해’로 동작하는 원리를 잘 설명해주고 있으니 한번 보시는 것을 추천드립니다!
The Three Pillars of Information Security
To understand cryptography, you first need to know the ‘three pillars of information security’, commonly called the ‘CIA’ triad.
- Confidentiality : secret information known only to authorized users.
- Integrity : information that hasn’t been altered from the original, or that is changed only by authorized means.
- Availability : guaranteeing that authorized users can use the information without disruption whenever they need it.
The purpose of cryptography is to guarantee ‘confidentiality’ by encrypting data, and additionally to provide ‘integrity’, a guarantee about whether data has been changed.
Encryption and Decryption
We said that ‘the purpose of cryptography is encrypting data’. So what exactly is encryption?

> Encryption and decryption
‘Encryption’ means taking plaintext, an ordinary message, and using an encryption algorithm to turn it into a coded message, ciphertext, that can’t be understood.
Conversely, ‘decryption’ means turning the ciphertext back into plaintext.
Types of Ciphers
Ciphers can be broadly divided into ‘two-way ciphers’ and ‘one-way ciphers’. ‘Direction’ here refers to encryption and decryption: two-way ciphers can both encrypt and decrypt, while one-way ciphers can only encrypt.

> Symmetric and asymmetric keys are two-way ciphers.
Confusion and Diffusion
The basic techniques behind all encryption can be broadly divided into ‘confusion’ and ‘diffusion’.

> Caesar cipher, Scytale cipher
Confusion
Confusion means replacing the characters of the plaintext with other letters, numbers, signs or symbols. The classic example is the Caesar technique.
Used by the Roman emperor Julius Caesar, this method writes A as D, B as E and so on; to read it, you shift each letter back by three to recover the original plaintext.
Diffusion
Diffusion is a technique that changes the positions of the letters. The classic example is the Scytale technique.
You wrap a strip of paper around a rod of a certain diameter and write the plaintext across it; when you unwind the paper, the letters are rearranged and the message can’t be read. Wrap it around a rod of the same diameter again and you can read the plaintext.
Key Management
- In the
Caesartechnique, the agreement to shift each letter by three - In the
Scytaletechnique, the diameter of the rod
These are the keys needed to turn the ciphertext back into plaintext.
You could say the most important thing in encryption is ‘building a strong algorithm’. But no matter how strong an encryption algorithm is, it’s useless if someone knows the key used for it.
So it’s fair to say that ‘how to manage the key safely’ is also at the heart of encryption.
Symmetric-key Cryptography
A typical cipher encrypts plaintext with a key and decrypts the ciphertext with the same key, which is what we call a ‘symmetric key’. ‘Symmetric key’ means the same key is used for both encryption and decryption.

> Symmetric key: the black key used for encryption is used again for decryption
Following the usual convention in cryptography, we’ll call ‘sender A’ Alice and ‘receiver B’ Bob.
Imagine the two of them communicating with encryption using the same key. Alice encrypts the plaintext with the key and sends it, and Bob decrypts the ciphertext with the same key, so they can communicate securely.
But there’s a basic prerequisite for the two of them to communicate this way.
‘To communicate with encryption, the sender and receiver must share the same key.’
This is where the problem comes in.
Sharing the Key

> Risk of the key being stolen through eavesdropping (the key distribution problem)
If Alice doesn’t send the key to Bob, Bob can’t decrypt the ciphertext he receives from her into plaintext. But if she does try to send the key, a hacker waiting for it could steal the key and decrypt the ciphertext.
This is fatal to ‘confidentiality’, the most important property of encryption. “We need to share the key, but we can’t even send it.” This is called the ‘key distribution problem’.
And we can’t make every communication channel 100% secure, either. So how can we share a key safely over an ‘insecure communication channel’?
Asymmetric-key Cryptography
There are a few ways to solve the ‘key distribution problem’. The best known is ‘asymmetric-key encryption’.
In this approach, there is one key for encryption and a separate key for decryption. Because the keys used for encryption and decryption differ, it’s called ‘asymmetric’. The two keys are:
- ‘A key anyone can see’ = ‘public key’
- ‘A key only you hold’ = ‘private key’
There’s one more important thing to remember. Anything encrypted with the private key or the public key can only be decrypted with the other key.
- What’s encrypted with the public key can only be decrypted with the private key
- What’s encrypted with the private key can only be decrypted with the public key
In other words, both keys can be used for encryption/decryption, but only the opposite key can undo what the other did.

> Asymmetric key : encrypting and decrypting with two keys
The basic flow looks like this:
- Alice uses ‘Bob’s public key’ to ‘encrypt’ the plaintext.
- Bob ‘decrypts’ the received ciphertext using ‘Bob’s private key’.
Because of this idea of a public key, it’s also called ‘public-key cryptography’.
When to Use Symmetric vs. Asymmetric Keys
So does all the encryption we use rely only on asymmetric keys? That’s half right and half wrong.
Asymmetric keys rely on a heavy computation, ‘prime factorization’. That’s why they aren’t well suited to encrypting large amounts of data. Symmetric keys, on the other hand, encrypt and decrypt much faster.
“Wait, what? Then if they’re not for encrypting data, what are they for?”
Of course, there are plenty of cases where asymmetric keys are used on their own. When encrypting data isn’t the goal, they’re a perfectly good fit, and many technologies already use them. The classic case is the ‘digital signature’. Its goal isn’t to encrypt data; its main purpose is to verify integrity (whether the data has been tampered with).
Using Asymmetric Keys for Symmetric Keys
Let’s sum up the pros and cons of symmetric and asymmetric keys once more.
| Pros | Cons | |
|---|---|---|
| Symmetric key | Fast and efficient | Hard to share the key |
| Asymmetric key | Secure key sharing | High computational cost |
Neither one seems quite enough on its own. So in practice, the two approaches are often combined.
Example : GitHub SSH Setup
Think about setting up SSH for GitHub. You create an asymmetric key pair yourself, keep the private key, and register the public key with GitHub.
- The public key on the GitHub server
- The private key that only you hold

> Anyone can see the public key a user registered with GitHub
Initial Connection Setup (Using Asymmetric Keys)
- The user creates an asymmetric key pair, keeps the private key and registers the public key with GitHub
- The user and GitHub generate the same symmetric key (session key) to use for SSH (Diffie-Hellman key exchange)
- The user creates a signature with the private key and sends it to the GitHub server
- The GitHub server verifies the signature by decrypting it with the public key

> The symmetric key is encrypted with the asymmetric key and delivered safely.
If the private key isn’t the pair of the public key registered with GitHub, authentication fails. Only someone with the right private key can get through, right?
Subsequent Communication (Using the Symmetric Key)
Since both sides now share the same session key, all further communication can safely encrypt/decrypt data with this symmetric key. This is a common pattern used not only in SSH but in many security protocols, including HTTPS.

Wrapping Up
That’s our look at symmetric and asymmetric keys. Let’s sum it up. 😊
- Symmetric keys have the ‘key distribution problem’.
- Asymmetric keys aren’t suited to encrypting data.
- The two are combined so each one’s strengths cover the other’s weaknesses
References
The videos below explain the basic principle of public keys and how they work through ‘prime factorization’ really well, so I recommend giving them a watch! (Note: the videos are in Korean.)