本文整理汇总了Java中android.security.KeyChain.getPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:Java KeyChain.getPrivateKey方法的具体用法?Java KeyChain.getPrivateKey怎么用?Java KeyChain.getPrivateKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.security.KeyChain
的用法示例。
在下文中一共展示了KeyChain.getPrivateKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchPrivateKey
import android.security.KeyChain; //导入方法依赖的package包/类
private PrivateKey fetchPrivateKey(Context context, String alias) throws KeyChainException,
InterruptedException, MessagingException {
PrivateKey privateKey = KeyChain.getPrivateKey(context, alias);
if (privateKey == null) {
throw new MessagingException("No private key found for: " + alias);
}
/*
* We need to keep reference to the first private key retrieved so
* it won't get garbage collected. If it will then the whole app
* will crash on Android < 4.2 with "Fatal signal 11 code=1". See
* https://code.google.com/p/android/issues/detail?id=62319
*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
savePrivateKeyReference(privateKey);
}
return privateKey;
}
示例2: getPrivateKey
import android.security.KeyChain; //导入方法依赖的package包/类
@Override
public PrivateKey getPrivateKey(String alias) {
try {
return KeyChain.getPrivateKey(mXmppConnectionService, alias);
} catch (Exception e) {
return null;
}
}
示例3: getPrivateKey
import android.security.KeyChain; //导入方法依赖的package包/类
@Override
public PrivateKey getPrivateKey(String alias) {
try {
return KeyChain.getPrivateKey(mXmppConnectionService, alias);
} catch (Exception e) {
return null;
}
}
示例4: signWithAlias
import android.security.KeyChain; //导入方法依赖的package包/类
public void signWithAlias(final String path,
final String alias,
final String name,
final String location,
final String reason,
byte[] imageData,
int page,
float x,
float y,
float width,
float height) throws IOException, InterruptedException, KeyChainException
{
byte[] buffer = new byte[BUFFER_SIZE];
this.callbackContext = callbackContext;
privKey = KeyChain.getPrivateKey(context, alias);
Certificate[] chain = KeyChain.getCertificateChain(context, alias);
File document = new File(path);
if (!(document != null && document.exists()))
new RuntimeException("");
Signature signature = new Signature(chain, privKey);
File outputPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
outputPath.mkdirs();
if (imageData.length > 0) {
ByteArrayInputStream image = new ByteArrayInputStream(imageData);
signature.setVisual(image, page, x, y, width, height);
System.err.println("page " + page + ":" + x + "," + y + " " + width + "x" + height);
}
signature.sign(path, outputPath.getAbsolutePath(), name, location, reason);
File outputDocument = new File(outputPath.getAbsolutePath() + "/" + document.getName() + ".signed.pdf");
File resultDocument = new File(path);
File removeDocument = new File(document.getPath() + ".unsigned.pdf");
document.renameTo(removeDocument);
outputDocument.renameTo(resultDocument);
return;
}