In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what is the difference between RSA JAVA key and C#". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
1. RSA syntax introduction
ASN.1, PKCS is the original and most important RSA public and private key syntax standard, maintained by RSA Lab.
ASN.1 and PKCS #1 both define types of public and private keys-serialized numbers.
For the next level of abstraction (proper wrapping), the commonly used combination is now: PKCS #8 private key, X.509 public key.
PKCS syntax is mainly used for private keys, and there are currently 10 internal standards. PKCS #8 is currently widely used in JAVA as a private key format.
The X.509 syntax is primarily used for public keys and is widely used in web browsers and SLLs.
The public and private keys of the three syntax standards can be transformed into each other, and the core is the integer value (modulus, PublicExponent, privateExponent) in ASN1 syntax, and the rest values can be calculated.
. NET uses the standard RSA format, and then encodes the numbers in base64 to generate XML for storage.
Java uses PKCS#8, X.509 public-private key syntax, storage is the corresponding JAVA class automatically generated base64 string.
Due to the difference in storage format, when converting and reading each other, you need to understand RSA related knowledge in order to correctly use classes to convert.
1.1 C#to Java
The public and private keys in C#are stored using XML strings, and the strings can be read directly when reading.
Since C#uses the standard RSA format, the core parameters (modulus, PublicExponent, privateExponent) of JAVA's RSAPublicKeySpec and RSAPrivateKeySpec configuration classes can be obtained after decoding the node values (Modulus-modulus, Exponent-PublicExponent, D-privateExponent) base64 in the corresponding XML. Then pass it into JAVA configuration class, and then generate corresponding RSA public and private keys according to configuration class.
View Code1.2 JAVA to C#
The public and private keys in JAVA are stored using base64. After decoding into byte arrays, the corresponding configuration objects (PKCS#8, X.509) need to be generated first, and RSA public and private keys are generated according to the configuration objects.
Private key:
C#uses the standard RSA format, and PKCS #1 syntax contains all integer values in the standard RSA format private key. To configure the object, you need to generate RSA object (RSAPrivateCrtKey) with PKCS#1 syntax, obtain object attributes, and construct private key XML by yourself.
View Code
Public key:
The public key is generated in the same way as the private key, and the configuration object generates a standard RSA object (RSA PublicKey).
View Code"RSA JAVA key and C#what is the difference" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.