java 代码如下:
ASN1InputStream inputStream = new ASN1InputStream(HSMUtil.hexString2ByteArr(spSecurity.getPubKey()));
RSAPublicKeyStructure struct = RSAPublicKeyStructure.getInstance(inputStream.readObject());
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(struct.getModulus(), struct.getPublicExponent());
KeyFactory factory = KeyFactory.getInstance("RSA");
PublicKey puk = factory.generatePublic(keySpec);
Cipher cipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, puk);
byte[] result = cipher.doFinal(HSMUtil.hexString2ByteArr(data));
这段代码是用 RSA 的公钥加密明文,如何用 ruby 实现?
我把 ruby1.9 支持的 ciphers 都输出来 (puts OpenSSL::Cipher.ciphers
) 了,但是没有看到RSA/ECB/PKCS1Padding,有谁知道的帮帮忙了