本文整理匯總了Java中org.bouncycastle.openpgp.PGPUtil.SHA256屬性的典型用法代碼示例。如果您正苦於以下問題:Java PGPUtil.SHA256屬性的具體用法?Java PGPUtil.SHA256怎麽用?Java PGPUtil.SHA256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.bouncycastle.openpgp.PGPUtil
的用法示例。
在下文中一共展示了PGPUtil.SHA256屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateTest
private void generateTest(
String message,
String type)
throws Exception
{
PGPSecretKey pgpSecKey = readSecretKey(new ByteArrayInputStream(secretKey));
PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey("".toCharArray(), "BC");
PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSecKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256, "BC");
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
Iterator it = pgpSecKey.getPublicKey().getUserIDs();
if (it.hasNext())
{
spGen.setSignerUserID(false, (String)it.next());
sGen.setHashedSubpackets(spGen.generate());
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ArmoredOutputStream aOut = new ArmoredOutputStream(bOut);
ByteArrayInputStream bIn = new ByteArrayInputStream(message.getBytes());
aOut.beginClearText(PGPUtil.SHA256);
//
// note the last \n in the file is ignored
//
ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
int lookAhead = readInputLine(lineOut, bIn);
processLine(aOut, sGen, lineOut.toByteArray());
if (lookAhead != -1)
{
do
{
lookAhead = readInputLine(lineOut, lookAhead, bIn);
sGen.update((byte)'\r');
sGen.update((byte)'\n');
processLine(aOut, sGen, lineOut.toByteArray());
}
while (lookAhead != -1);
}
aOut.endClearText();
BCPGOutputStream bcpgOut = new BCPGOutputStream(aOut);
sGen.generate().encode(bcpgOut);
aOut.close();
messageTest(new String(bOut.toByteArray()), type);
}