Hello everyone.In last blog we have seen how RSA encryption technique practically works. We generated the public-private key pair from CryptoServiceProvider class present in .Net framework but in real world we never use the key generated from this class. The reason behind this is every time whenever your application using RSA implementation is fired, there will be a new pair of key generated and it will not use old key pair. Imagine a scenario where the public key need to be stored in database.In such case every time a new key pair is generated you have to store that in database overriding the previous one. Also generating keys from this class has some drawbacks.
Drawbacks:
1. Overhead of overriding the newly generated key-pair in database each time the application is fired
2. Padding problem
3. If using cross platform encryption-decryption (e.g. encryption in .Net and decryption in java or vice-versa) then encoding,padding,mode etc are the issues which can be encountered.
To avoid this one should always use Certificates for generating public-private key pair. It has lots of advantages as compared to old mechanism.
Consider a real world scenario where you want to make a payment through Credit card. The client need to pass Credit card details along with some other information to the application that will make the payment. The client application is built in .Net and the receiver application is built in Java. As we all know that credit card details are vulnerable to be hacked so we will protect them using some mechanism while passing it through network. We might use any encryption technique to hide the original details or masking the value. In such case if we are using RSA encryption technique then cross platform encryption decryption becomes a serious problem as we have discussed above.
So to overcome this type of scenario one can install certificates on both client and receiver machine. This will automatically adjust all padding, mode and encoding related issue while using cross platform encryption decryption process.
In this blog, we will discuss that the receiver has the public private key pair generated from Certificates.He is providing the public key in string format so that we can easily stored that key in database and whenever required we can access that public key from our database and can use it for encryption.
But as we seen in last blog that to use encrypt inbuilt function one has to convert the key in string format to key in XML string format. After that only we can pass that key for encryption purpose.
So we will see how to convert a key in string format to key in xml string format through code:
For local use of RSA encryption we can use key generated from .Net inbuilt class. If you this key is stored in string format in database and you need to convert it to XML string format then use below code

Similarly if the key is generated from certificate and you want to convert it to XML string format then use below function


Note: To use above function for certificate import below namespace in your code:
Drawbacks:
1. Overhead of overriding the newly generated key-pair in database each time the application is fired
2. Padding problem
3. If using cross platform encryption-decryption (e.g. encryption in .Net and decryption in java or vice-versa) then encoding,padding,mode etc are the issues which can be encountered.
To avoid this one should always use Certificates for generating public-private key pair. It has lots of advantages as compared to old mechanism.
Consider a real world scenario where you want to make a payment through Credit card. The client need to pass Credit card details along with some other information to the application that will make the payment. The client application is built in .Net and the receiver application is built in Java. As we all know that credit card details are vulnerable to be hacked so we will protect them using some mechanism while passing it through network. We might use any encryption technique to hide the original details or masking the value. In such case if we are using RSA encryption technique then cross platform encryption decryption becomes a serious problem as we have discussed above.
So to overcome this type of scenario one can install certificates on both client and receiver machine. This will automatically adjust all padding, mode and encoding related issue while using cross platform encryption decryption process.
In this blog, we will discuss that the receiver has the public private key pair generated from Certificates.He is providing the public key in string format so that we can easily stored that key in database and whenever required we can access that public key from our database and can use it for encryption.
But as we seen in last blog that to use encrypt inbuilt function one has to convert the key in string format to key in XML string format. After that only we can pass that key for encryption purpose.
So we will see how to convert a key in string format to key in xml string format through code:
For local use of RSA encryption we can use key generated from .Net inbuilt class. If you this key is stored in string format in database and you need to convert it to XML string format then use below code

Similarly if the key is generated from certificate and you want to convert it to XML string format then use below function


Note: To use above function for certificate import below namespace in your code:
- System.Security.Cryptography.X509Certificates
And rest of the procedure is similar to encrypt and decrypt as seen in previous blog.
RSA implementation : RSA-Implementaion
Thanks for reading and feel free to leave your feedback.
No comments:
Post a Comment