This commit is contained in:
gurkenhabicht 2024-02-18 21:23:15 +01:00
parent 513a004f9f
commit a5305627d2
2 changed files with 36 additions and 14 deletions

View File

@ -54,8 +54,6 @@ Show parameters of the private key
openssl rsa -in $PRIVATE_KEY -text -noout
```
### Create RSA Key
Generate an OpenSSL RSA key via
@ -97,14 +95,16 @@ openssl rsautl -decrypt -in $CIPHER -out $PLAIN_TEXT -inkey $PRIVATE_KEY
### Read Parameters of a DH Keys
* Output of a DH key is done the following way
Output of a DH key is done the following way
```sh
openssl dhparam -in $PRIVATE_KEY -text -noout
```
### Create DH Key
* A Diffie-Hellman key can be created via
A Diffie-Hellman key can be created via
```sh
openssl dhparam -out $PRIVATE_KEY 4096
```
@ -113,7 +113,7 @@ openssl dhparam -out $PRIVATE_KEY 4096
### Encrypt AES
* Encrypt AES
Encrypt AES
```sh
openssl aes-256-cbc -e -in $PLAIN_TEXT -out $CIPHER
@ -121,7 +121,8 @@ openssl aes-256-cbc -e -in $PLAIN_TEXT -out $CIPHER
### Decrypt AES
* Decrypt AES
Decrypt AES
```sh
openssl aes-256-cbc -d -in $CIPHER -out $PLAIN_TEXT
```
@ -130,14 +131,16 @@ openssl aes-256-cbc -d -in $CIPHER -out $PLAIN_TEXT
### Encrypt PBKDF2
* Encrypt file via PBKDF2 with 128000 iterations
Encrypt file via PBKDF2 with 128000 iterations
```sh
openssl aes-256-cbc -pbkdf2 -iter 128000 -e -in $PLAIN_TEXT -out $CIPHER
```
### Decrypt PBKDF2
* Decrypt file via PBKDF2 with an iteration of 128000
Decrypt file via PBKDF2 with an iteration of 128000
```sh
openssl aes-256-cbc -pbkdf2 -iter 128000 -d -in $CIPHER -out $PLAIN_TEXT
```
@ -151,4 +154,3 @@ openssl aes-256-cbc -pbkdf2 -iter 128000 -d -in $CIPHER -out $PLAIN_TEXT
```sh
openssl ec -pubin -in publickey.pem -noout -text
```

View File

@ -1,7 +1,20 @@
# RSA
* `p * q = n`
* Coprime Phi is calculated either by [Euler Totient](https://en.wikipedia.org/wiki/Euler's_totient_function) or [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) via [euclidean algorithm](https://crypto.stanford.edu/pbc/notes/numbertheory/euclid.html)
What is interesting about an RSA key:
`e` is a constant, often it is 65537
`n` is the modulus, `p * q = n` through factorization
Coprime `phi` is calculated either by [Euler
Totient](https://en.wikipedia.org/wiki/Euler's_totient_function) or [greatest
common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) via
[euclidean
algorithm](https://crypto.stanford.edu/pbc/notes/numbertheory/euclid.html)
`d` is the modular inverse of e and phi
---
$$
1 < \phi < n
@ -10,7 +23,7 @@ $$
There is also
$$
\phi = (p-1) * (q-1)
$$$
$$
Encryption, public key `e` is a prime between 2 and phi
$$
@ -36,8 +49,13 @@ for i in range (phi + 1, phi + foo):
possible_d.append()
```
* \\( Cipher = msg ** d mod $\phi$ \\)
* \\( Cleartext = cipher ** e mod $\phi$ )
$$
Cipher = msg ** d mod $\phi$
$$
$$
Cleartext = cipher ** e mod $\phi$
$$
## Euklid
@ -179,6 +197,7 @@ def isqrt(n):
x=y
y=(x+n//x)//2
return x
def fermat(n):
t0=isqrt(n)+1
counter=0
@ -214,6 +233,7 @@ def isqrt(n):
x=y
y=(x+n//x)//2
return x
def fermat(n):
t0=isqrt(n)+1
counter=0