我正在使用AndroidStudio,我有如下所示的项目:
蓝圈内的是myLib.myLib还需要使用红色圆圈内的外部库和一个apache包(绿色圆圈).
所以我想让整个事情成为一个单独的.jar,所以我可以在另一个项目中使用它.
一步一步的指南将非常感激,我是开发人员世界的初学者.
谢谢!
很抱歉问一个特定的问题,但是我需要在java代码中生成一个'签名',就像ruby中的以下代码行一样:
signature = OpenSSL::PKey::RSA.new(File.read("PUBLIC_PEM_PATH")).public_encrypt('SECRET_KEY')
我有.pem密钥文件和SECRET_KEY,它是这样的:F6qxlwQTYWRM3gRfgftryKJHKYZiGXdoy5lDm4
我怎样才能做到这一点 ?
谢谢!
更新1 我试过这个:
File pubKeyFile = new File(keyFileName);
DataInputStream inputStream;
byte[] signature = null;
try {
inputStream = new DataInputStream(new FileInputStream(pubKeyFile));
byte[] pubKeyBytes = new byte[(int)pubKeyFile.length()];
inputStream.readFully(pubKeyBytes);
inputStream.close();
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(pubKeyBytes);
RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubSpec);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
signature = cipher.doFinal(secretKey.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
return signature;
Run Code Online (Sandbox Code Playgroud)
并得到这个错误:
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
Run Code Online (Sandbox Code Playgroud)
UPDATE2 我设法从.pem文件加载公钥.但是现在,我从密码中得到了一个错误.
public static byte[] …
Run Code Online (Sandbox Code Playgroud)