由于近期經(jīng)常被改犇,,我的有些犇犇會(huì)使用RSA/ECB/PKCS1Padding 加密,。我的公鑰:
Modulus: 7749508816481769130958656717979283807090064162903164284448125194652436835418455841001455979629062396710853788700110904825475002409879758932825196227887201
Public 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編碼的密文。
輸入樣例:
7749508816481769130958656717979283807090064162903164284448125194652436835418455841001455979629062396710853788700110904825475002409879758932825196227887201
65537
VQMtiDl6jutupZi6T5ooTUejV02LYoz7fYjFwUNy4L7hmLQFeLzJqPQculd3j3/oHF0/Y9nk5A+nHHtgQ4fu/A==
|