mirror of
https://github.com/billbuchanan/appliedcrypto.git
synced 2026-02-20 13:50:42 +00:00
Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -71,15 +71,6 @@ Using the following Web page, determine the owner of the key, and the ID on the
|
||||
|
||||
[https://asecuritysite.com/encryption/pgp1](https://asecuritysite.com/pgp/pgp1)
|
||||
|
||||
Now, save the file to newpub.gpg on your Ubuntu instance, and then determine the information that is provided with the command:
|
||||
|
||||
```
|
||||
gpg newpub.gpg
|
||||
```
|
||||
|
||||
By searching on-line, can you find the public key of three famous people, and view their key details, and can you discover some of the details of their keys (eg User ID, key encryption method, key size, etc)?
|
||||
|
||||
|
||||
|
||||
By searching on-line, what is an ASCII Armored Message?
|
||||
|
||||
@@ -322,55 +313,7 @@ How does secp128k1, secp256k1 and secp512r1 different in the parameters used? Pe
|
||||
If you want to see an example of ECC, try [here](https://asecuritysite.com/encryption/ecc)
|
||||
|
||||
## D Elliptic Curve Encryption
|
||||
### D.1
|
||||
In the following Bob and Alice create elliptic curve key pairs. Bob can encrypt a message for Alice with her public key, and she can decrypt with her private key. Copy and paste the program from here:
|
||||
|
||||
https://asecuritysite.com/encryption/elc
|
||||
|
||||
Code used:
|
||||
|
||||
```python
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
import binascii
|
||||
import sys
|
||||
|
||||
private_key = ec.generate_private_key(ec.SECP256K1())
|
||||
|
||||
|
||||
vals = private_key.private_numbers()
|
||||
no_bits=vals.private_value.bit_length()
|
||||
print (f"Private key value: {vals.private_value}. Number of bits {no_bits}")
|
||||
|
||||
public_key = private_key.public_key()
|
||||
vals=public_key.public_numbers()
|
||||
|
||||
enc_point=binascii.b2a_hex(vals.encode_point()).decode()
|
||||
|
||||
print (f"\nPublic key encoded point: {enc_point} \nx={enc_point[2:(len(enc_point)-2)//2+2]} \ny={enc_point[(len(enc_point)-2)//2+2:]}")
|
||||
|
||||
|
||||
pem = private_key.private_bytes(encoding=serialization.Encoding.PEM,format=serialization.PrivateFormat.PKCS8,encryption_algorithm=serialization.NoEncryption())
|
||||
|
||||
der = private_key.private_bytes(encoding=serialization.Encoding.DER,format=serialization.PrivateFormat.PKCS8,encryption_algorithm=serialization.NoEncryption())
|
||||
|
||||
|
||||
|
||||
print ("\nPrivate key (PEM):\n",pem.decode())
|
||||
print ("Private key (DER):\n",binascii.b2a_hex(der))
|
||||
|
||||
pem = public_key.public_bytes(encoding=serialization.Encoding.PEM,format=serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
|
||||
der = public_key.public_bytes(encoding=serialization.Encoding.DER,format=serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
|
||||
print ("\nPublic key (PEM):\n",pem.decode())
|
||||
print ("Public key (DER):\n",binascii.b2a_hex(der))
|
||||
|
||||
```
|
||||
|
||||
For a message of “Hello. Alice”, what is the ciphertext sent (just include the first four characters):
|
||||
|
||||
**NOTE**: Python 3.5 is not working using the above code example. Please use Python 3.8 !
|
||||
|
||||
|
||||
### D.2
|
||||
|
||||
Reference in New Issue
Block a user