由于近期经常被改犇,我的有些犇犇会使用RSA/ECB/PKCS1Padding
加密。我的公钥:
Modulus: 7749508816481769130958656717979283807090064162903164284448125194652436835418455841001455979629062396710853788700110904825475002409879758932825196227887201Public Exponent: 65537
解密代码:(直接拿某谷IDE跑就没问题)
import java.math.BigInteger;import java.nio.charset.StandardCharsets;import java.security.*;import java.security.spec.*;import java.util.Base64;import java.util.Scanner;import javax.crypto.Cipher;public class Main { public static void main(String[] args) throws Exception { Scanner sca = new Scanner(System.in); BigInteger mod = sca.nextBigInteger(); BigInteger expo = sca.nextBigInteger(); String str = sca.next(); sca.close(); RSAPublicKeySpec spec = new RSAPublicKeySpec(mod, expo); KeyFactory factory = KeyFactory.getInstance("RSA"); PublicKey key = factory.generatePublic(spec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] data = cipher.doFinal(Base64.getDecoder().decode(str)); String ret = new String(data, StandardCharsets.UTF_8); System.out.println(ret); }}
输入格式:共三行,第一行为Modulus,第二行为Public Exponent,第三行为Base64编码的密文。
输入样例:
774950881648176913095865671797928380709006416290316428444812519465243683541845584100145597962906239671085378870011090482547500240987975893282519622788720165537VQMtiDl6jutupZi6T5ooTUejV02LYoz7fYjFwUNy4L7hmLQFeLzJqPQculd3j3/oHF0/Y9nk5A+nHHtgQ4fu/A==
联系客服