This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8008|Reply: 6

[Source] [Actual combat] State Secret 4 (SM4) uses .NET and Java to decrypt each other

[Copy link]
Posted on 9/12/2022 10:26:24 PM | | | |
Requirements: Due to the need to connect with a third party on the friend project, the data is encrypted using the National Secret 4 (SM4) algorithm during transmission, and both parties need to encrypt and decrypt the data.

SM4.0 (formerly known as SMS4.0) is a block cryptography standard adopted by the government of the People's Republic of China, released by the State Cryptography Administration on March 21, 2012. The relevant standard is "GM/T 0002-2012 "SM4 Block Cipher Algorithm" (formerly SMS4 Block Cipher Algorithm)".

Information Security Technology SM4 Block Cryptography Algorithm:The hyperlink login is visible.

Java projects

A new maven project has been created, and the hutool tool has been introduced, using the SM4 algorithm encapsulated in hutool, and the pom file is introduced as follows:

Documentation:The hyperlink login is visible.

.NET project

The .NET project needs to be introduced in my encapsulationSw.ChinaEncryptSMPackages, which support .NET Framework and .NET Core projects, use the nuget command as follows:


Address:The hyperlink login is visible.

Test the .NET and Java encryption results

.NET code:

Java code:

You can see that in the case of the same key and iv,The result is the same after encryption, as shown in the figure below:



.NET encryption and decryption and Java decryption

Here is an omission of the code that uses Java to encrypt .NET encryption, and you can draw inferences from one example.

.NET code:

Java code:

As shown below:

The encryption result is as follows:
rG50B+Ah6k0FqvvKItc2TDJnt9HcDIG9OyjBqkiiAlI=
The decryption results are as follows:
Test small scum itsvse.com



(End)




Previous:Learn to create and release NuGet packages in 3 minutes
Next:Extract the files in the unzipped .msi installation package
Posted on 9/12/2022 11:19:18 PM |
Learn to learn
Posted on 9/19/2022 9:39:02 AM |
Learn the JAVA.NET of national secret exchange
Posted on 9/24/2022 9:29:33 AM |

Learn the JAVA.NET of national secret exchange
Posted on 10/18/2022 7:31:37 PM |
Just in time, take a look
Posted on 1/4/2023 5:37:20 PM |

Just in time, take a look! ~~~~~
 Landlord| Posted on 6/9/2023 8:09:39 PM |
The SM4 algorithm randomly generates SM4 keys and IVs, and currently only supports 128 bits (i.e. 16 bytes of key).


The C# code looks like this:



Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com