Sign with processing Maybe it can be used to create an IDE (though people who make IDEs can make it without looking at it ...) library Please install ZipSigner and Spongy Castle import
import java.security.KeyStore;
import java.io.*;
import android.os.Environment;
import javax.crypto.SecretKey;
import javax.crypto.KeyGenerator;
import kellinwood.security.zipsigner.ZipSigner;
import java.io.InputStream;
import kellinwood.security.zipsigner.optional.CustomKeySigner;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import java.net.*;
If processing
if (!hasPermission("android.permission.WRITE_EXTERNAL_STORAGE"))requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "initLocation");
Can be done with If it is java, please add WRITE_EXTERNAL_STORAGE without permission
KeyStore ks;
void createKey(String keyName,String keyPassword,String Alias,String AliasPassword){
try{
String directory=Environment.getExternalStorageDirectory()+"/"+keyName+"."+KeyStore.getDefaultType();
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, keyPassword.toCharArray());
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(128);
SecretKey mySecretKey=keyGen.generateKey();
KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(mySecretKey);
ks.setEntry(Alias, skEntry, new KeyStore.PasswordProtection(AliasPassword.toCharArray()));
File file=new File(directory);
FileOutputStream fos = new FileOutputStream(file);
ks.store(fos, keyPassword.toCharArray());
}catch(Exception e){
e.printStackTrace();
}
}
Go out
void sign(String keystore,String keystorePassword,String keyAlias,String StringkeyAliasPassword,String inFilename,String outputFilename){
try {
ZipSigner signer = new ZipSigner();
CustomKeySigner.signZip(signer, keystore, keystorePassword.toCharArray(), keyAlias, keyAliasPassword.toCharArray(), "SHA1WITHRSA", inFilename, outputFilename);
}catch (Exception e) {
e.printStackTrace();
}
}
Go out
It took a lot of time because there were few explanations in Japanese, but the work itself was simple.
Recommended Posts