java.apk_[转载]java打apk包

package test;import java.io.BufferedReader;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.File;import java.io.FileInputStream;im...
摘要由CSDN通过智能技术生成

package test;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.DataInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FilterOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.PrintStream;

import java.security.DigestOutputStream;

import java.security.GeneralSecurityException;

import java.security.Key;

import java.security.KeyFactory;

import java.security.MessageDigest;

import java.security.PrivateKey;

import java.security.Signature;

import java.security.SignatureException;

import java.security.cert.CertificateException;

import java.security.cert.CertificateFactory;

import java.security.cert.X509Certificate;

import java.security.spec.InvalidKeySpecException;

import java.security.spec.KeySpec;

import java.security.spec.PKCS8EncodedKeySpec;

import java.util.Enumeration;

import java.util.Map;

import java.util.jar.Attributes;

import java.util.jar.JarEntry;

import java.util.jar.JarFile;

import java.util.jar.JarOutputStream;

import java.util.jar.Manifest;

import javax.crypto.Cipher;

import javax.crypto.EncryptedPrivateKeyInfo;

import javax.crypto.SecretKeyFactory;

import javax.crypto.spec.PBEKeySpec;

import org.bouncycastle.util.encoders.Base64;

import sun.misc.BASE64Encoder;

import sun.security.pkcs.ContentInfo;

import sun.security.pkcs.PKCS7;

import sun.security.pkcs.SignerInfo;

import sun.security.x509.AlgorithmId;

import sun.security.x509.X500Name;

import ccit.security.PrivateKeyFromDER;

public class SignApk {

private static X509Certificate readPublicKey(File

file) throws IOException,

GeneralSecurityException{

FileInputStream input = new

FileInputStream(file);

try {

CertificateFactory

cf = CertificateFactory.getInstance("X.509");

return

(X509Certificate) cf.generateCertificate(input);

} finally {

input.close();

}

}

private static String readPassword(File keyFile)

{

// TODO: use

Console.readPassword() when it's available.

System.out.print("Enter

password for " + keyFile

+

" (password will not be hidden): ");

System.out.flush();

BufferedReader stdin = new

BufferedReader(new InputStreamReader(

System.in));

try {

return

stdin.readLine();

} catch (IOException ex)

{

return

null;

}

}

private static KeySpec decryptPrivateKey(byte[]

encryptedPrivateKey,

File keyFile)

throws GeneralSecurityException{

EncryptedPrivateKeyInfo

epkInfo;

try {

epkInfo = new

EncryptedPrivateKeyInfo(encryptedPrivateKey);

} catch (IOException ex)

{

// Probably

not an encrypted key.

return

null;

}

char[] password =

readPassword(keyFile).toCharArray();

SecretKeyFactory skFactory =

SecretKeyFactory.getInstance(epkInfo

.getAlgName());

Ke

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值