本文整理汇总了Java中org.bouncycastle.asn1.nist.NISTObjectIdentifiers.id_sha256方法的典型用法代码示例。如果您正苦于以下问题:Java NISTObjectIdentifiers.id_sha256方法的具体用法?Java NISTObjectIdentifiers.id_sha256怎么用?Java NISTObjectIdentifiers.id_sha256使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.nist.NISTObjectIdentifiers
的用法示例。
在下文中一共展示了NISTObjectIdentifiers.id_sha256方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOIDForHashAlgorithm
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public static ASN1ObjectIdentifier getOIDForHashAlgorithm(int hashAlgorithm)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return PKCSObjectIdentifiers.md5;
case HashAlgorithm.sha1:
return X509ObjectIdentifiers.id_SHA1;
case HashAlgorithm.sha224:
return NISTObjectIdentifiers.id_sha224;
case HashAlgorithm.sha256:
return NISTObjectIdentifiers.id_sha256;
case HashAlgorithm.sha384:
return NISTObjectIdentifiers.id_sha384;
case HashAlgorithm.sha512:
return NISTObjectIdentifiers.id_sha512;
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例2: getOIDForHashAlgorithm
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return PKCSObjectIdentifiers.md5;
case HashAlgorithm.sha1:
return X509ObjectIdentifiers.id_SHA1;
case HashAlgorithm.sha224:
return NISTObjectIdentifiers.id_sha224;
case HashAlgorithm.sha256:
return NISTObjectIdentifiers.id_sha256;
case HashAlgorithm.sha384:
return NISTObjectIdentifiers.id_sha384;
case HashAlgorithm.sha512:
return NISTObjectIdentifiers.id_sha512;
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例3: getValue
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
@Override
public Attribute getValue() throws SignerException {
try {
X509Certificate cert = (X509Certificate) certificates[0];
X509Certificate issuerCert = (X509Certificate) certificates[1];
Digest digest = DigestFactory.getInstance().factoryDefault();
digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
byte[] certHash = digest.digest(cert.getEncoded());
X500Name dirName = new X500Name(issuerCert.getSubjectX500Principal().getName());
GeneralName name = new GeneralName(dirName);
GeneralNames issuer = new GeneralNames(name);
ASN1Integer serialNumber = new ASN1Integer(cert.getSerialNumber());
IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber);
AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);// SHA-256
ESSCertIDv2 essCertIDv2 = new ESSCertIDv2(algId, certHash, issuerSerial);
// return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new DERSequence(essCertIDv2)));
return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new DERSequence(
new ASN1Encodable[] { new DERSequence(essCertIDv2) })));
} catch (CertificateEncodingException ex) {
throw new SignerException(ex.getMessage());
}
}
示例4: performTest
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public void performTest()
throws Exception
{
// check getInstance on default algorithm.
byte[] digest = new byte [256];
ESSCertIDv2 essCertIdv2 = new ESSCertIDv2(new AlgorithmIdentifier(
NISTObjectIdentifiers.id_sha256), digest);
ASN1Primitive asn1Object = essCertIdv2.toASN1Primitive();
ESSCertIDv2.getInstance(asn1Object);
}
示例5: getValue
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
@Override
public Attribute getValue() throws SignerException {
try {
int chainSize = certificates.length -1;
OtherCertID[] arrayOtherCertID = new OtherCertID[chainSize];
for (int i = 1; i <= chainSize; i++ ){
X509Certificate issuerCert = null;
X509Certificate cert = (X509Certificate) certificates[i];
if (i < chainSize){
issuerCert = (X509Certificate) certificates[i+1];
}else{ // raiz
issuerCert = (X509Certificate) certificates[i];
}
Digest digest = DigestFactory.getInstance().factoryDefault();
digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
byte[] certHash = digest.digest(cert.getEncoded());
X500Name dirName = new X500Name(issuerCert.getSubjectX500Principal().getName());
GeneralName name = new GeneralName(dirName);
GeneralNames issuer = new GeneralNames(name);
ASN1Integer serialNumber = new ASN1Integer(cert.getSerialNumber());
IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber);
AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);
OtherCertID otherCertID = new OtherCertID(algId, certHash, issuerSerial);
arrayOtherCertID[i -1] = otherCertID;
}
return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new ASN1Encodable[] { new DERSequence(arrayOtherCertID) }));
} catch (CertificateEncodingException e) {
throw new SignerException(e.getMessage());
}
}
示例6: JceKTSKeyWrapper
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public JceKTSKeyWrapper(PublicKey publicKey, String symmetricWrappingAlg, int keySizeInBits, byte[] partyUInfo, byte[] partyVInfo)
{
super(new AlgorithmIdentifier(PKCSObjectIdentifiers.id_rsa_KEM, new GenericHybridParameters(new AlgorithmIdentifier(ISOIECObjectIdentifiers.id_kem_rsa, new RsaKemParameters(new AlgorithmIdentifier(X9ObjectIdentifiers.id_kdf_kdf3, new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256)), (keySizeInBits + 7) / 8)), JceSymmetricKeyWrapper.determineKeyEncAlg(symmetricWrappingAlg, keySizeInBits))));
this.publicKey = publicKey;
this.symmetricWrappingAlg = symmetricWrappingAlg;
this.keySizeInBits = keySizeInBits;
this.partyUInfo = Arrays.clone(partyUInfo);
this.partyVInfo = Arrays.clone(partyVInfo);
}
示例7: Builder
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
/**
* Basic builder.
*
* @param algorithmName the algorithm name for the secret key we use for wrapping.
* @param keySizeInBits the size of the wrapping key we want to produce in bits.
* @param otherInfo the otherInfo/IV encoding to be applied to the KDF.
*/
public Builder(String algorithmName, int keySizeInBits, byte[] otherInfo)
{
this.algorithmName = algorithmName;
this.keySizeInBits = keySizeInBits;
this.kdfAlgorithm = new AlgorithmIdentifier(X9ObjectIdentifiers.id_kdf_kdf3, new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256));
this.otherInfo = (otherInfo == null) ? new byte[0] : Arrays.clone(otherInfo);
}
示例8: digestInfoSha256
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
@Test
public void digestInfoSha256() throws Exception {
byte[] message = "hello world".getBytes();
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
byte[] digest = messageDigest.digest(message);
LOG.debug("Digest: " + new String(Hex.encodeHex(digest)));
DERObjectIdentifier hashAlgoId = NISTObjectIdentifiers.id_sha256;
DigestInfo digestInfo = new DigestInfo(new AlgorithmIdentifier(hashAlgoId, DERNull.INSTANCE), digest);
byte[] encodedDigestInfo = digestInfo.getEncoded();
LOG.debug("Digest Info: " + new String(Hex.encodeHex(encodedDigestInfo)));
}
示例9: testAsGreenhandUpdated
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/33305800/difference-between-sha256withrsa-and-sha256-then-rsa">
* Difference between SHA256withRSA and SHA256 then RSA
* </a>
* <p>
* This method is the updated code provided by the OP. As expected it shows two equal signatures.
* The OP's observations seem to differ, though.
* </p>
*/
public void testAsGreenhandUpdated(PrivateKey privateKey) throws GeneralSecurityException, IOException
{
System.out.println("\nGreenhandUpdated:");
String s = "1234";
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(s.getBytes());
byte[] outputDigest = messageDigest.digest();
AlgorithmIdentifier sha256Aid = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, DERNull.INSTANCE);
DigestInfo di = new DigestInfo(sha256Aid, outputDigest);
//sign SHA256 with RSA
Signature rsaSignature = Signature.getInstance("RSA");
rsaSignature.initSign(privateKey);
byte[] encodedDigestInfo = di.toASN1Primitive().getEncoded();
rsaSignature.update(encodedDigestInfo);
byte[] signed = rsaSignature.sign();
System.out.println("method 1: "+bytesToHex(signed));
System.out.println(" hash: " + bytesToHex(outputDigest));
System.out.println(" algo: " + sha256Aid.getAlgorithm());
System.out.println(" info: " + bytesToHex(encodedDigestInfo));
//compute SHA256withRSA as a single step
Signature rsaSha256Signature = Signature.getInstance("SHA256withRSA");
rsaSha256Signature.initSign(privateKey);
rsaSha256Signature.update(s.getBytes());
byte[] signed2 = rsaSha256Signature.sign();
System.out.println("method 2: "+bytesToHex(signed2));
}
示例10: SHA256
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public SHA256()
{
super(NISTObjectIdentifiers.id_sha256, new SHA256Digest(), new PKCS1Encoding(new RSABlindedEngine()));
}
示例11: SHA256
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public SHA256()
{
super(NISTObjectIdentifiers.id_sha256, new SHA256Digest(), new PKCS1Encoding(new NativeRSAEngine()));
}
示例12: SHA256
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
/**
* Creates a new instance configured with the default configuration.
*/
public SHA256() {
super(NISTObjectIdentifiers.id_sha256,
getDigest("SHA-256"),
new PKCS1Encoding(new NativeRSABlindedEngine()));
}
示例13: SHA256WithRSAEncryption
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public SHA256WithRSAEncryption()
{
super(NISTObjectIdentifiers.id_sha256, new SHA256Digest(), new PKCS1Encoding(new RSABlindedEngine()));
}
示例14: testGenerateWithMetadataAndDifferentAlgorithmIdentifier
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public void testGenerateWithMetadataAndDifferentAlgorithmIdentifier()
throws Exception
{
cmsTimeStampedDataGenerator.setMetaData(true, fileInput, "TXT");
BcDigestCalculatorProvider calculatorProvider = new BcDigestCalculatorProvider();
ASN1ObjectIdentifier algIdentifier = NISTObjectIdentifiers.id_sha224;
DigestCalculator hashCalculator = calculatorProvider.get(new AlgorithmIdentifier(algIdentifier));
cmsTimeStampedDataGenerator.initialiseMessageImprintDigestCalculator(hashCalculator);
hashCalculator.getOutputStream().write(baseData);
hashCalculator.getOutputStream().close();
byte[] requestData = hashCalculator.getDigest();
TimeStampToken timeStampToken = createTimeStampToken(requestData, algIdentifier);
CMSTimeStampedData cmsTimeStampedData = cmsTimeStampedDataGenerator.generate(timeStampToken, baseData);
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
algIdentifier = NISTObjectIdentifiers.id_sha224;
break;
case 1:
algIdentifier = NISTObjectIdentifiers.id_sha256;
break;
case 2:
algIdentifier = NISTObjectIdentifiers.id_sha384;
break;
case 3:
algIdentifier = NISTObjectIdentifiers.id_sha512;
break;
}
hashCalculator = calculatorProvider.get(new AlgorithmIdentifier(algIdentifier));
byte[] newRequestData = cmsTimeStampedData.calculateNextHash(hashCalculator);
TimeStampToken newTimeStampToken = createTimeStampToken(newRequestData, algIdentifier);
cmsTimeStampedData = cmsTimeStampedData.addTimeStamp(newTimeStampToken);
}
byte[] timeStampedData = cmsTimeStampedData.getEncoded();
metadataCheck(timeStampedData);
metadataParserCheck(timeStampedData);
}
示例15: getAlgorithmIdentifier
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; //导入方法依赖的package包/类
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);
}