我用JAVA生成了一個公鑰如下:
System.out.println(publicKey.getPublicKey());
輸出:modulus:154308594144468705348294760484396264219304223307125368116140288659005422830
11489867478404495635728307309845313276126541903154766024976823588585215138754477992
96802915396931308077347778973425837411602815233405546695183536389616670156153124753
50767041053961957188628650343640790505255765999004862716823611888529
public exponent: 65537
用這個modulus的值加密不了,我看網上的公鑰都是這樣子的5q4F3crOuN4OG68Dko7EZl5wYn+FokohvMm6m/NFmMJIGBhYnJ9/8JKQMxndka8GafQ9BU/LASFtvbrfNsyA6TfP2wMalewfWF0GBT5AviGouGqt9I9BMrvBfTttU5OMqD2rF+fQ23WMTi+UYzY/9kZB7Rys7A1oIFWnsnB0Jnc=AQAB
請問這個modulus是不是要轉換一下 怎麼轉換呢?有沒懂的大神幫下忙
模加密是:BigInteger n=pbk.getModulus();
System.out.println("e= "+e);
System.out.println("n= "+n);
// 明文 m
byte ptext[]=s.getBytes("UTF8");
BigInteger m=new BigInteger(ptext);
// 計算密文c,打印
BigInteger c=m.modPow(e,n);
System.out.println("c= "+c);
下面的格式是Base64格式的:
RSAPublicKey pbk=(RSAPublicKey) x509.getPublicKey();
System.out.println(Base64.encode(pbk.getEncoded()));