Position: Home page » Blockchain » RSA algorithm blockchain
RSA algorithm blockchain
Publish: 2021-05-03 06:16:40
1.
In today's era of high development of the Internet, we are using the Internet more and more frequently, which has become an indispensable and important tool in our life. In particular, the mobile phone used for Internet communication has been used as a medium. In today's era, we are using mobile payment more and more, There are more and more ways to move. So what is digital currency? What do you know about it{ But generally speaking, it is a form of money< p> Finally, for such a form of transaction, it's all for the convenience of our daily life, and it's also for serving our own broad masses of people, so we don't have to worry about the advantages and disadvantages of digital currency and mobile payment
2. RSA algorithm is the most commonly used asymmetric encryption algorithm, which can be used for both encryption and digital signature. RSA Security is based on the difficulty of large number decomposition. Its public key and private key are functions of a pair of large primes (100 to 200 decimal digits or more). The difficulty of recovering plaintext from a public key and ciphertext is equivalent to decomposing the proct of two large prime numbers
we can understand the working principle of RSA through a simple example. For convenience of calculation. In the following example, only prime numbers P, Q, and e with small values are selected. Suppose that user a needs to encrypt the plaintext "key" through RSA and pass it to user B. the process is as follows: design public and private keys (E, n) and (D, n)
let P = 3, q = 11, then n = P × q=3 × 11=33 f(n)=(p-1)(q-1)=2 × 10=20 If e = 3, (3 and 20 are coprime), then E × D ≡ 1 mod f (n), i.e. 3 × d≡1 mod 20 We find that when d = 7, e × D ≡ 1 mod f (n) congruence equation holds. Therefore, let d = 7. So we can design a pair of public and private keys, encryption key (public key) is Ku = (E, n) = (3,33), decryption key (private key) is Kr = (D, n) = (7,33)
Digital English. The plaintext information is digitized and each block is divided into two numbers. It is assumed that the plaintext alphabet is an alphabetic list of values. The plaintext information of the grouped key is: 11, 05, 25
plaintext encryption. The user encryption key (3,33) encrypts the digital plaintext packet information into ciphertext. According to C ≡ me (MOD n),
C1 (ciphertext) ≡ M1 (plaintext) ^ e (MOD n) = = 11 ≡ 11 ^ 3 mod 33
C2 (ciphertext) ≡ M2 (plaintext) ^ e (MOD n) = = 26 ≡ 05 ^ 3 mod 33
C3 (ciphertext) ≡ m3 (plaintext) ^ e (MOD n) = = 16 ≡ 25 ^ 3 mod 33< So the ciphertext is 11.26.16
decrypt the ciphertext. If user B receives the ciphertext and decrypts it, it only needs to calculate, that is:
M1 (plaintext) ≡ C1 (ciphertext) ^ D (MOD n) = = 11 ≡ 11 ^ 7 Mod 33
M2 (plaintext) ≡ C2 (ciphertext) ^ D (MOD n) = = 05 ≡ 26 ^ 7 Mod 33
m3 (plaintext) ≡ C3 (ciphertext) ^ D (MOD n) = = 25 ≡ 16 ^ 7 Mod 33
converted to plaintext 11.05.25. According to the above coding table, we can convert it into English and get the original "key" after recovery
of course, the actual application is much more complicated than this. Because the length of RSA algorithm's public key and private key (molus length) can only be 1024 or even 2048 bits to ensure security, so the selection of P, Q and E, the generation of public key and private key, encryption and decryption molus index operation all have certain calculation proceres, which need to rely on the computer to complete at high speed.
we can understand the working principle of RSA through a simple example. For convenience of calculation. In the following example, only prime numbers P, Q, and e with small values are selected. Suppose that user a needs to encrypt the plaintext "key" through RSA and pass it to user B. the process is as follows: design public and private keys (E, n) and (D, n)
let P = 3, q = 11, then n = P × q=3 × 11=33 f(n)=(p-1)(q-1)=2 × 10=20 If e = 3, (3 and 20 are coprime), then E × D ≡ 1 mod f (n), i.e. 3 × d≡1 mod 20 We find that when d = 7, e × D ≡ 1 mod f (n) congruence equation holds. Therefore, let d = 7. So we can design a pair of public and private keys, encryption key (public key) is Ku = (E, n) = (3,33), decryption key (private key) is Kr = (D, n) = (7,33)
Digital English. The plaintext information is digitized and each block is divided into two numbers. It is assumed that the plaintext alphabet is an alphabetic list of values. The plaintext information of the grouped key is: 11, 05, 25
plaintext encryption. The user encryption key (3,33) encrypts the digital plaintext packet information into ciphertext. According to C ≡ me (MOD n),
C1 (ciphertext) ≡ M1 (plaintext) ^ e (MOD n) = = 11 ≡ 11 ^ 3 mod 33
C2 (ciphertext) ≡ M2 (plaintext) ^ e (MOD n) = = 26 ≡ 05 ^ 3 mod 33
C3 (ciphertext) ≡ m3 (plaintext) ^ e (MOD n) = = 16 ≡ 25 ^ 3 mod 33< So the ciphertext is 11.26.16
decrypt the ciphertext. If user B receives the ciphertext and decrypts it, it only needs to calculate, that is:
M1 (plaintext) ≡ C1 (ciphertext) ^ D (MOD n) = = 11 ≡ 11 ^ 7 Mod 33
M2 (plaintext) ≡ C2 (ciphertext) ^ D (MOD n) = = 05 ≡ 26 ^ 7 Mod 33
m3 (plaintext) ≡ C3 (ciphertext) ^ D (MOD n) = = 25 ≡ 16 ^ 7 Mod 33
converted to plaintext 11.05.25. According to the above coding table, we can convert it into English and get the original "key" after recovery
of course, the actual application is much more complicated than this. Because the length of RSA algorithm's public key and private key (molus length) can only be 1024 or even 2048 bits to ensure security, so the selection of P, Q and E, the generation of public key and private key, encryption and decryption molus index operation all have certain calculation proceres, which need to rely on the computer to complete at high speed.
3. I just reviewed the algorithm knowledge about RSA, let me tell you:
RSA public key cryptosystem:
1. Key pair generation: randomly generate two large prime numbers: P, Q, n = P × Q
2. Randomly generating encryption key e: selecting a random e such that GCD (E, (p-1) * (Q-1)) = 1 is to select a random e such that E and (p-1) * (Q-1) are mutually prime. Usually, e is also prime< In this way, the public key pair (n, e) proces
3. Calculate the decryption key D: calculate a number d, if e * D mod (p-1) * (Q-1) = 1, where N and D are also prime< In this way, a private key pair (n, d)
is generated. The sender sends a certain number of m to the person holding the secret key (n, d)
sends the ciphertext C = m ^ e mod n
the receiver decrypts M = C ^ D mod n by using the private key
of course, it needs a special algorithm to calculate the molus index, otherwise the computer can't do it: the algorithm is as follows:
# include & lt; iostream>< br />#include < cmath>< br />using namespace std;< br />
int exp_ mod(int a,int n,int z)
{
int exp = 1;< br /> int x = a % z;< br /> while (n> 0)
{
if(n%2==1)
exp = (exp * x) % z;< br /> x = (x * x) % z;< br /> n = n/2;< br /> }
return exp;< br />
}
int main()
{
int a,n,z;< br /> cout<& lt; & quot; Please input base: & quot< br /> cin>& gt; a;< br /> cout<& lt; & quot; Please input index: & quot< br /> cin>& gt; n;< br /> cout<& lt; & quot; Please enter the molus to be modified: & quot< br /> cin>& gt; z;< br /> int result = exp_ mod(a,n,z);< br />
cout<& lt; & quot; The result is: & quot& lt;& lt; result<& lt; endl;< br /> cout<& lt;& quot; General algorithm results & quot& lt;& lt; long(pow(a,n))%z <& lt; endl;/* Double pow (int
x, int y) to find the Y power of X * /
return 0
}
this is the C + + source code of a ^ b Mod C
I hope it can help you. If it's good, don't forget to add points!
RSA public key cryptosystem:
1. Key pair generation: randomly generate two large prime numbers: P, Q, n = P × Q
2. Randomly generating encryption key e: selecting a random e such that GCD (E, (p-1) * (Q-1)) = 1 is to select a random e such that E and (p-1) * (Q-1) are mutually prime. Usually, e is also prime< In this way, the public key pair (n, e) proces
3. Calculate the decryption key D: calculate a number d, if e * D mod (p-1) * (Q-1) = 1, where N and D are also prime< In this way, a private key pair (n, d)
is generated. The sender sends a certain number of m to the person holding the secret key (n, d)
sends the ciphertext C = m ^ e mod n
the receiver decrypts M = C ^ D mod n by using the private key
of course, it needs a special algorithm to calculate the molus index, otherwise the computer can't do it: the algorithm is as follows:
# include & lt; iostream>< br />#include < cmath>< br />using namespace std;< br />
int exp_ mod(int a,int n,int z)
{
int exp = 1;< br /> int x = a % z;< br /> while (n> 0)
{
if(n%2==1)
exp = (exp * x) % z;< br /> x = (x * x) % z;< br /> n = n/2;< br /> }
return exp;< br />
}
int main()
{
int a,n,z;< br /> cout<& lt; & quot; Please input base: & quot< br /> cin>& gt; a;< br /> cout<& lt; & quot; Please input index: & quot< br /> cin>& gt; n;< br /> cout<& lt; & quot; Please enter the molus to be modified: & quot< br /> cin>& gt; z;< br /> int result = exp_ mod(a,n,z);< br />
cout<& lt; & quot; The result is: & quot& lt;& lt; result<& lt; endl;< br /> cout<& lt;& quot; General algorithm results & quot& lt;& lt; long(pow(a,n))%z <& lt; endl;/* Double pow (int
x, int y) to find the Y power of X * /
return 0
}
this is the C + + source code of a ^ b Mod C
I hope it can help you. If it's good, don't forget to add points!
4. C. The hypothesis of impossible factorization of large numbers
5. Mathematical principle of RSA algorithm
mathematical principle of RSA algorithm:
first find out three numbers, P, Q, R,
where P and Q are two different prime numbers, and R is coprime number with (p-1) (Q-1)
P, Q and R are private keys. Next, find m, so that RM = = 1 mod (p-1) (Q-1)... This m must exist, because R and (p-1) (Q-1) are coprime, and we can get it by rolling division method. Then, calculate n = PQ..... M, n these two numbers are public key
the encoding process is that if the data is a, it is regarded as a large integer, assuming that a & lt; N.. If a & gt= If n, a is expressed as s-carry (S & lt= n. Generally, s = 2 ^ t), then each digit is less than N, and then it is encoded by segments... Next, B = = a ^ m mod n, (0 & lt= b < n) The decoding process is to calculate C = = B ^ R mod PQ (0 & lt= c < If a third party wiretaps, he will get several numbers: m, n (= PQ), b... if he wants to decode, he must find a way to get r... therefore, he must first decompose n into prime factors to prevent him from decomposing, The most effective method is to find two very large prime numbers P and Q, which makes it difficult for the third to factorize; Theorem & gt; If P, q are different prime numbers, RM = = 1 mod (p-1) (Q-1), a is any positive integer, B = = a ^ m mod PQ, C = = B ^ R mod PQ, then C = = a mod PQ. The process of proof will use Fermat's theorem, which is described as follows: m is any prime number, n is any integer, then n ^ m = = n mod m (in other words, If n and m are coprime, then n ^ (m-1) = = 1 mod m) using some basic knowledge of group theory, we can easily prove the.. & lt; Proof & gt; Because RM = = 1 mod (p-1) (Q-1), RM = K (p-1) (Q-1) + 1, where k is an integer because it is preserved multiplicative in Molo (x = = y mod Z and u = = V mod z = & gt; Xu = = YV mod z), so C = = B ^ R = = (a ^ m) ^ R = = a ^ (RM) = = a ^ (K (p-1) (Q-1) + 1) mod PQ 1. If a is neither a multiple of P nor a multiple of Q, then a ^ (p-1) = = 1 mod p (Fermat's theorem) = & gt; A ^ (K (p-1) (Q-1)) = = 1 mod p a ^ (Q-1) = = 1 mod Q (Fermat's theorem) = & gt; A ^ (K (p-1) (Q-1)) = = 1 mod Q, so P and Q can divide a ^ (K (p-1) (Q-1)) - 1 = & gt; PQ | a ^ (K (p-1) (Q-1)) - 1, that is, a ^ (K (p-1) (Q-1)) = = 1 mod PQ = & gt; C = = a ^ (K (p-1) (Q-1) + 1) = = a mod PQ 2. If a is a multiple of P, but not a multiple of Q, then a ^ (Q-1) = = 1 mod Q (Fermat's theorem) = & gt; a^(k(p-1)(q-1)) == 1 mod q => c == a^(k(p-1)(q-1)+1) == a mod q => Q | C - A for P | a = & gt; c == a^(k(p-1)(q-1)+1) == 0 mod p => Therefore, PQ | C - a = & gt; C = = a mod PQ 3. If a is a multiple of Q, but not a multiple of P, the proof is the same as above 4. If a is a multiple of both P and Q, then PQ | a = & gt; c == a^(k(p-1)(q-1)+1) == 0 mod pq => pq | c - a => C = = a mod PQ Q.E.D. this theorem shows that when a is encoded to B and then decoded to C, a = = C mod n (n = PQ)... But we limit 0 & lt= a < n, 0 <= c < n. So that is to say, a is equal to C, so this process can really achieve the function of encoding and decoding
mathematical principle of RSA algorithm:
first find out three numbers, P, Q, R,
where P and Q are two different prime numbers, and R is coprime number with (p-1) (Q-1)
P, Q and R are private keys. Next, find m, so that RM = = 1 mod (p-1) (Q-1)... This m must exist, because R and (p-1) (Q-1) are coprime, and we can get it by rolling division method. Then, calculate n = PQ..... M, n these two numbers are public key
the encoding process is that if the data is a, it is regarded as a large integer, assuming that a & lt; N.. If a & gt= If n, a is expressed as s-carry (S & lt= n. Generally, s = 2 ^ t), then each digit is less than N, and then it is encoded by segments... Next, B = = a ^ m mod n, (0 & lt= b < n) The decoding process is to calculate C = = B ^ R mod PQ (0 & lt= c < If a third party wiretaps, he will get several numbers: m, n (= PQ), b... if he wants to decode, he must find a way to get r... therefore, he must first decompose n into prime factors to prevent him from decomposing, The most effective method is to find two very large prime numbers P and Q, which makes it difficult for the third to factorize; Theorem & gt; If P, q are different prime numbers, RM = = 1 mod (p-1) (Q-1), a is any positive integer, B = = a ^ m mod PQ, C = = B ^ R mod PQ, then C = = a mod PQ. The process of proof will use Fermat's theorem, which is described as follows: m is any prime number, n is any integer, then n ^ m = = n mod m (in other words, If n and m are coprime, then n ^ (m-1) = = 1 mod m) using some basic knowledge of group theory, we can easily prove the.. & lt; Proof & gt; Because RM = = 1 mod (p-1) (Q-1), RM = K (p-1) (Q-1) + 1, where k is an integer because it is preserved multiplicative in Molo (x = = y mod Z and u = = V mod z = & gt; Xu = = YV mod z), so C = = B ^ R = = (a ^ m) ^ R = = a ^ (RM) = = a ^ (K (p-1) (Q-1) + 1) mod PQ 1. If a is neither a multiple of P nor a multiple of Q, then a ^ (p-1) = = 1 mod p (Fermat's theorem) = & gt; A ^ (K (p-1) (Q-1)) = = 1 mod p a ^ (Q-1) = = 1 mod Q (Fermat's theorem) = & gt; A ^ (K (p-1) (Q-1)) = = 1 mod Q, so P and Q can divide a ^ (K (p-1) (Q-1)) - 1 = & gt; PQ | a ^ (K (p-1) (Q-1)) - 1, that is, a ^ (K (p-1) (Q-1)) = = 1 mod PQ = & gt; C = = a ^ (K (p-1) (Q-1) + 1) = = a mod PQ 2. If a is a multiple of P, but not a multiple of Q, then a ^ (Q-1) = = 1 mod Q (Fermat's theorem) = & gt; a^(k(p-1)(q-1)) == 1 mod q => c == a^(k(p-1)(q-1)+1) == a mod q => Q | C - A for P | a = & gt; c == a^(k(p-1)(q-1)+1) == 0 mod p => Therefore, PQ | C - a = & gt; C = = a mod PQ 3. If a is a multiple of Q, but not a multiple of P, the proof is the same as above 4. If a is a multiple of both P and Q, then PQ | a = & gt; c == a^(k(p-1)(q-1)+1) == 0 mod pq => pq | c - a => C = = a mod PQ Q.E.D. this theorem shows that when a is encoded to B and then decoded to C, a = = C mod n (n = PQ)... But we limit 0 & lt= a < n, 0 <= c < n. So that is to say, a is equal to C, so this process can really achieve the function of encoding and decoding
6. B
What do you want to ask
RSA is an operation based on large numbers
it needs n, P, Q, DP and DQ parameters
P and Q are two prime numbers
What do you want to ask
RSA is an operation based on large numbers
it needs n, P, Q, DP and DQ parameters
P and Q are two prime numbers
7. DES algorithm is called data encryption standard, that is, data encryption algorithm. It was successfully researched and published by IBM in 1975. There are three entry parameters of DES algorithm: key, data and mode. The key is 8 bytes, 64 bits in total, which is the working key of DES algorithm; Data is also 8 bytes and 64 bits, which is the data to be encrypted or decrypted; Mode is the working mode of DES, there are two kinds: encryption or decryption
DES algorithm transforms 64 bit plaintext input block into 64 bit ciphertext output block, and the key it uses is also 64 bit. The algorithm is mainly divided into two steps:
1
DES algorithm transforms 64 bit plaintext input block into 64 bit ciphertext output block, and the key it uses is also 64 bit. The algorithm is mainly divided into two steps:
1
8. import java.security.*;
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
public class Password_Test {
public static void main(String[] args) {
try {
new Password_Test();
Encryption_RSA();
} catch (Exception e) {
e.printStackTrace();
}
}
public Password_Test() throws Exception {// 构造方法 创建公钥和私钥
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");//生成实现RSA算法的KeyPairGenerator对象
kpg.initialize(1024);// 初始化确定密钥的大小
KeyPair kp = kpg.genKeyPair();// 生成密钥对
PublicKey pbkey = kp.getPublic();// 创建公钥
PrivateKey prkey = kp.getPrivate();// 创建私钥
// 保存公钥
FileOutputStream file1 = new FileOutputStream("D:/temp/Skey_RSA_pub.dat");
ObjectOutputStream ob1 = new ObjectOutputStream(file1);//创建ObjectOutputStream对象
ob1.writeObject(pbkey); //将指定的对象写入 ObjectOutputStream
// 保存私钥
FileOutputStream file2 = new FileOutputStream("D:/temp/Skey_RSA_priv.dat");
ObjectOutputStream ob2 = new ObjectOutputStream(file2);
ob2.writeObject(prkey);
}
public static void Encryption_RSA() throws Exception {
System.out.println("根据公钥生成密文:"+"\n");
String string = "I am a student";
// 获取公钥及参数e,n
FileInputStream f_in = new FileInputStream("D:/temp/Skey_RSA_pub.dat");
ObjectInputStream o_in = new ObjectInputStream(f_in);
RSAPublicKey pbk = (RSAPublicKey) o_in.readObject();
BigInteger e = pbk.getPublicExponent();//返回此公钥的指数
BigInteger n = pbk.getMolus();//返回此公钥的模
System.out.println("公钥的指数 e= " + e);
System.out.println("公钥的模 n= " + n);
// 明文 bit
byte bt[] = string.getBytes("UTF8");
BigInteger bit = new BigInteger(bt);
// 计算密文c,打印
BigInteger mi = bit.modPow(e, n);//生成密文
System.out.println("生成密文为: " + mi+"\n\n");//打印密文
// 保存密文
String save = mi.toString();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("D:/temp/Enc_RSA.dat")));
out.write(save, 0, save.length());
out.close();
Decrypt_RSA();
}
public static void Decrypt_RSA() throws Exception {
System.out.println("根据私钥破解密文:"+"\n");
// 读取密文
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("D:/temp/Enc_RSA.dat")));
String ctext = in.readLine();
BigInteger mi = new BigInteger(ctext);
// 读取私钥
FileInputStream f = new FileInputStream("D:/temp/Skey_RSA_priv.dat");
ObjectInputStream b = new ObjectInputStream(f);
RSAPrivateKey prk = (RSAPrivateKey) b.readObject();
BigInteger d = prk.getPrivateExponent();//返回此私钥的指数
BigInteger n = prk.getMolus();//返回此私钥的模
System.out.println("私钥的指数 d= " + d);
System.out.println("私钥的模 n= " + n);
BigInteger jie = mi.modPow(d, n);//进行解密操作
System.out.println("m= " + jie); // 显示解密结果
byte[] mt = jie.toByteArray();
System.out.println("解密后的文本内容为: ");
for (int i = 0; i < mt.length; i++) {
System.out.print((char) mt[i]);
}
}
}
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
public class Password_Test {
public static void main(String[] args) {
try {
new Password_Test();
Encryption_RSA();
} catch (Exception e) {
e.printStackTrace();
}
}
public Password_Test() throws Exception {// 构造方法 创建公钥和私钥
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");//生成实现RSA算法的KeyPairGenerator对象
kpg.initialize(1024);// 初始化确定密钥的大小
KeyPair kp = kpg.genKeyPair();// 生成密钥对
PublicKey pbkey = kp.getPublic();// 创建公钥
PrivateKey prkey = kp.getPrivate();// 创建私钥
// 保存公钥
FileOutputStream file1 = new FileOutputStream("D:/temp/Skey_RSA_pub.dat");
ObjectOutputStream ob1 = new ObjectOutputStream(file1);//创建ObjectOutputStream对象
ob1.writeObject(pbkey); //将指定的对象写入 ObjectOutputStream
// 保存私钥
FileOutputStream file2 = new FileOutputStream("D:/temp/Skey_RSA_priv.dat");
ObjectOutputStream ob2 = new ObjectOutputStream(file2);
ob2.writeObject(prkey);
}
public static void Encryption_RSA() throws Exception {
System.out.println("根据公钥生成密文:"+"\n");
String string = "I am a student";
// 获取公钥及参数e,n
FileInputStream f_in = new FileInputStream("D:/temp/Skey_RSA_pub.dat");
ObjectInputStream o_in = new ObjectInputStream(f_in);
RSAPublicKey pbk = (RSAPublicKey) o_in.readObject();
BigInteger e = pbk.getPublicExponent();//返回此公钥的指数
BigInteger n = pbk.getMolus();//返回此公钥的模
System.out.println("公钥的指数 e= " + e);
System.out.println("公钥的模 n= " + n);
// 明文 bit
byte bt[] = string.getBytes("UTF8");
BigInteger bit = new BigInteger(bt);
// 计算密文c,打印
BigInteger mi = bit.modPow(e, n);//生成密文
System.out.println("生成密文为: " + mi+"\n\n");//打印密文
// 保存密文
String save = mi.toString();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("D:/temp/Enc_RSA.dat")));
out.write(save, 0, save.length());
out.close();
Decrypt_RSA();
}
public static void Decrypt_RSA() throws Exception {
System.out.println("根据私钥破解密文:"+"\n");
// 读取密文
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("D:/temp/Enc_RSA.dat")));
String ctext = in.readLine();
BigInteger mi = new BigInteger(ctext);
// 读取私钥
FileInputStream f = new FileInputStream("D:/temp/Skey_RSA_priv.dat");
ObjectInputStream b = new ObjectInputStream(f);
RSAPrivateKey prk = (RSAPrivateKey) b.readObject();
BigInteger d = prk.getPrivateExponent();//返回此私钥的指数
BigInteger n = prk.getMolus();//返回此私钥的模
System.out.println("私钥的指数 d= " + d);
System.out.println("私钥的模 n= " + n);
BigInteger jie = mi.modPow(d, n);//进行解密操作
System.out.println("m= " + jie); // 显示解密结果
byte[] mt = jie.toByteArray();
System.out.println("解密后的文本内容为: ");
for (int i = 0; i < mt.length; i++) {
System.out.print((char) mt[i]);
}
}
}
9. RSA algorithm is an asymmetric cryptographic algorithm. The so-called asymmetric means that the algorithm needs a pair of keys. If one key is used for encryption, the other key is used for decryption
RSA algorithm involves three parameters, N, E1 and E2
where n is the proct of two large prime numbers P and Q, and the number of bits occupied by the binary representation of n is the so-called key length
E1 and E2 are a pair of related values. E1 can be taken arbitrarily, but E1 and (p-1) * (Q-1) are required to be coprime; Then select E2, which requires (E2 * E1) mod ((p-1) * (Q-1)) = 1
(N and E1), (N and E2) are key pairs< If a is plaintext and B is ciphertext, then a = B ^ E1 mod n; B=A^e2 mod n
E1 and E2 can be used interchangeably, that is:
A = B ^ E2 mod n; B=A^e1 mod n
supplementary answer:
there are two situations to encrypt plaintext:
1. When you send encrypted data to a friend, you want only your friend to decrypt it. In this case, you need to first obtain the public key of your friend's key pair, e and n. Then use this key to encrypt, so that only your friends can decrypt the ciphertext, because the corresponding private key is only owned by your friends
2. When you send a piece of data to a friend and attach your digital signature, you need to perform MD5 and other operations on your data to get the & quot; Fingerprints;, And then to & quot; Fingerprint & quot; Encryption, which uses the private key that is not public in your own key pair. After receiving the data, your friend uses the same operation to obtain the data fingerprint, and then decrypts the encrypted fingerprint with your public key. By comparing the decryption result with the fingerprint calculated by himself, we can determine whether the data is actually sent by you and whether it has been tampered in the transmission process
the key is usually issued by a certain organization (such as Ca Center). Of course, you can also create your own key, but in this way, your key is not authoritative
in terms of calculation, just calculate according to the formula. If your encryption strength is 1024 bits, the result will fill 0 in front of the valid data to make up the insufficient bits. The complement of 0 does not affect the decryption operation.
RSA algorithm involves three parameters, N, E1 and E2
where n is the proct of two large prime numbers P and Q, and the number of bits occupied by the binary representation of n is the so-called key length
E1 and E2 are a pair of related values. E1 can be taken arbitrarily, but E1 and (p-1) * (Q-1) are required to be coprime; Then select E2, which requires (E2 * E1) mod ((p-1) * (Q-1)) = 1
(N and E1), (N and E2) are key pairs< If a is plaintext and B is ciphertext, then a = B ^ E1 mod n; B=A^e2 mod n
E1 and E2 can be used interchangeably, that is:
A = B ^ E2 mod n; B=A^e1 mod n
supplementary answer:
there are two situations to encrypt plaintext:
1. When you send encrypted data to a friend, you want only your friend to decrypt it. In this case, you need to first obtain the public key of your friend's key pair, e and n. Then use this key to encrypt, so that only your friends can decrypt the ciphertext, because the corresponding private key is only owned by your friends
2. When you send a piece of data to a friend and attach your digital signature, you need to perform MD5 and other operations on your data to get the & quot; Fingerprints;, And then to & quot; Fingerprint & quot; Encryption, which uses the private key that is not public in your own key pair. After receiving the data, your friend uses the same operation to obtain the data fingerprint, and then decrypts the encrypted fingerprint with your public key. By comparing the decryption result with the fingerprint calculated by himself, we can determine whether the data is actually sent by you and whether it has been tampered in the transmission process
the key is usually issued by a certain organization (such as Ca Center). Of course, you can also create your own key, but in this way, your key is not authoritative
in terms of calculation, just calculate according to the formula. If your encryption strength is 1024 bits, the result will fill 0 in front of the valid data to make up the insufficient bits. The complement of 0 does not affect the decryption operation.
10. Bitcoin will cost US $1W soon. Although it is not cheap, there are many hedging tools to rece the risk of this entry point. For example, the contract trading of okex exchange can hedge the spot risk very well.
Hot content