Digital encryption algorithm

One: Introduction to Digital Signature

What is a digital signature? A message digest algorithm with keys (public key, private key) is used to verify data integrity, authenticate data source, and resist denial. In layman's terms, it is to prove that a certain message or document was sent/approved by the person himself, and this is used more often. Such as electronic contracts, bank signing, electronic authorization, etc. So his safety is something we must consider. The commonly used signature algorithms in digital signatures are RSA, DSA, ECDSA, etc.

Two: the basic process of digital signature

The basic process is as follows:

(1) The sender generates the public key and private key pair of the asymmetric encryption algorithm, and announces its public key and signature algorithm (for example, sha256WithRSAEncryption);

(2) The sender first calculates the digital digest of the message sent, and then uses the private key to encrypt the digest to generate a digital signature;

(3) When receiving a message purporting to be from XXX, the receiver first queries XXX’s published public key and signature algorithm;

(4) The receiver uses the public key to decrypt the digital signature and compare it with the calculated digital digest. If the comparison is consistent, then the message comes from XXX and has not been tampered with.

The security premise of the above process is based on the following two points:

① The signature algorithm of the sender cannot be cracked, and the private key has not been leaked

②The public key and signature algorithm queried by the receiver are true

Three: Analyze the DSA signature algorithm in eclipse

(1) Analysis in the main class Mainactivity

Analyze these custom methods:

  • getPublicKey(keyMap);//Get the public key

  • getPrivateKey(keyMap);//Get the private key

  • be.encode(publicKey));//public key encryption

  • be.encode(privateKey));//private key encryption

  • DSA.sign(data.getBytes(), privateKey);//Speak private key to sign

  • DSA.verify(data.getBytes(), publicKey, sign)+"");//Verify

Digital encryption algorithm

(2) Analyze in custom DSA

Several important methods

  • generateKeyPair: Generate a key pair
  • getPublic to get the public key
  • getPrivate: Get the private key
  • X509EncodedKeySpec: Create a new X509EncodedKeySpec according to the given encoding key

Digital encryption algorithm
Digital encryption algorithm
Digital encryption algorithm
Digital encryption algorithm

summary

1. Introduce the knowledge and implementation principles of digital signature series.

2. Analyze the code of DSA signature algorithm in eclipse.

Guess you like

Origin blog.51cto.com/15002917/2561023