## Introduction to Digital Signature Cryptography

Digital signature cryptography is nothing but a process of encrypting the digital certificates, using various encryption algorithms like Message digest, message digest 5, Secure Hash algorithm, ElGamal encryption, etc that encrypt the digital certificates to avoid the attacks on digital certificates and provides the security.

The Cryptography of a digital signature is possible with two key terms:

- Private Key
- Public Key

**Private Key**: The account holder holds a key which is a random hexadecimal number. Private Key will be confidential to the account holder rather than exposed to the real world

**Public Key**: A random hexadecimal number that is shared publicly. To create a public cryptography digital signature the message will be signed digitally first, then it is encrypted with the private key of the sender and with the public key of the receiver. To decrypt the messages shared between the sender and receiver, the receiver has to decrypt the inner layer of the information with the Public key of the sender and decrypt the outer layer of the information using the private key which receiver holds.

### Digital Signature Cryptography Architecture

To perform digital signature using cryptography, the following has to be carried out:

In the sender end, the message/information should be encrypted using a hashing function with the sender’s private key. The information will be forwarded to the receiver’s end with the intermediate digital signature model. In the receiver’s end, the receiver verifies the digital signature by decrypting the information received using the hashing function. The decryption will be performed by extracting the inner layer using the public key and the outer layer extracted using the private key. One major challenge to securely share information is to send the message in an encrypted format. In Cryptography with digital signature having public key shared with the external world, there is a chance someone might spoof the encryption.

4.5 (5,317 ratings)

View Course

Encryption of digital signatures can be carried out in two major forms:

#### 1. Digital Signature Followed by Encryption

In this method, the sender signature is exploited by the receiver and the information is shared with the external party without encryption. As this form is less secured this is not preferable in industry.

#### 2. Encryption Followed by Digital Signature

The most common approach in the industry is encryption followed by a digital signature where the sender sends the encrypted data with the digital signature. When the receiver receives the message on its end it will decrypt the message shared by the sender using the sender’s public key and the receiver’s private key.

### Cryptography Digital Signature with RSA

The following code snippet will explain how cryptography with digital signature is implemented in real-time in python and also will explain how the encryption and decryption are carried out with digital signature using RSA. To perform cryptography with digital signature we require the pycrypto package installed, then write the below snippet.

`importCrypto`

fromPublicKey importRSA

fromCrypto import Random

To perform cryptography with the digital signature, we require the initialization of private key and public key. We create a function to generate RSA keys which will have a private key and public key:

`defrsa_keys():`

l=1024

private_key = RSA.generate(l, Random.new().read)

public_key = private_key.publickey()

return private_key, public_key

The above snippet returns the private key and public key.

#### 1. Encryption Function

`defencrypt(public_key,text):`

c_text=public_key.encrypt(text,32)[0]
val_cipher=base64.b64encode(c_text)

return val_cipher

To encrypt the message, we use the above code which will take rsa_publickey and text as parameters to the encrypt function. The encrypt function will perform the public key encryption and generate the cipher, the generated cipher is returned when the function call is invoked.

#### 2. Decryption Function

`defdecrypt(private_key,val_cipher):`

d_cipher = base64.b64decode(val_cipher)

text = private_key.decrypt(d_cipher)

return text

Cryptography with a digital signature using public-key encryption and text decryption carried out using the private key. To understand the meaning of encrypted text shared as a cipher, we have created a decryption function. The function takes private_key and the cipher generated by the encryption function. Using the decode method it creates a decrypted cipher and using the decrypt method it will return the decrypted text.

#### 3. Implementation

In this sample we will look at how the encryption of text is carried out and how it is decrypted back to original text using the private key is explained. The function of encrypt and decrypt will be used in the sample to show how to cipher will be encrypted and decrypted.

**Code:**

`importCrypto`

fromPublicKey importRSA

fromCrypto import Random

importbase64

defrsa_keys():

l=1024

private_key = RSA.generate(l, Random.new().read)

public_key = private_key.publickey()

returnprivate_key, public_key

defencrypt(public_key,plain_text):

c_text=public_key.encrypt(plain_text,32)[0]
val_cipher=base64.b64encode(c_text)

returnval_cipher

defdecrypt(private_key,val_cipher):

d_cipher = base64.b64decode(val_cipher)

text = private_key.decrypt(d_cipher)

returntext

private_key,public_key=rsa_keys()

txt=b"Hello Peers!"

enc_cipher=encrypt(public_key,txt)

print('**'*10)

print("The ecncrypted text is {}".format(enc_cipher))

print('**'*10)

dec_cipher=decrypt(private_key,enc_cipher) #decryption

print("The decrypted cipher text is {}".format(dec_cipher))

print('**'*10)

**Output:**

As we can see the input text “Hello Peers!” passed to encrypt function is encrypted using the public key. The encrypted cipher passed as param to the decrypt function decrypts the original message shared using the receiver private key. To perform digital signature with cryptography will require the method ‘sign’ and ‘verify’, the sign will be performed by the sender using the private key, when the information is transferred to the receiver, verify function is carried out using the public key.

### Merits & Demerits of Cryptography Digital Signature

Following are the merits and demerits explained.

#### Merits

- Improve the security of information transfer.
- Improve the workflow more digitalized.
- Better customer experience.
- Improve Business Efficiency and legal validity.
- Reduces manual effort and saves time.

#### Demerits

- It requires a lot of time for verification.
- It does not guard against vulnerabilities
- Infrastructure and setting up of cryptography is not cost-friendly.

### Conclusion

In the modern digital world, the digital signature algorithm with cryptography plays a vital role in providing a safe and secure environment and is one of the better tools for authentication. In the growing technological world, it will play its crucial part in terms of security against threats and vulnerabilities.

### Recommended Articles

This is a guide to Digital Signature Cryptography. Here we discuss the Digital Signature Cryptography Architecture along with code implementation. You can also go through our other suggested articles to learn more –