Java Code Examples for org.bouncycastle.asn1.nist.NISTObjectIdentifiers#id_sha512()
The following examples show how to use
org.bouncycastle.asn1.nist.NISTObjectIdentifiers#id_sha512() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RsaSigningClient.java From protect with MIT License | 6 votes |
public static BigInteger EMSA_PKCS1_V1_5_ENCODE(byte[] input, final BigInteger modulus) throws NoSuchAlgorithmException, IOException { // Digest the input final MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM); final byte[] digest = md.digest(input); // Create a digest info consisting of the algorithm id and the hash final AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, DERNull.INSTANCE); final DigestInfo digestInfo = new DigestInfo(algId, digest); final byte[] message = digestInfo.getEncoded(ASN1Encoding.DER); // Do PKCS1 padding final byte[] block = new byte[(modulus.bitLength() / 8) - 1]; System.arraycopy(message, 0, block, block.length - message.length, message.length); block[0] = 0x01; // type code 1 for (int i = 1; i != block.length - message.length - 1; i++) { block[i] = (byte) 0xFF; } return new BigInteger(1, block); }
Example 2
Source File: RsaCertificateAuthorityClient.java From protect with MIT License | 6 votes |
/*** Static Methods ***/ private static BigInteger EMSA_PKCS1_V1_5_ENCODE(byte[] input, final BigInteger modulus) throws NoSuchAlgorithmException, IOException { // Digest the input final MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM); final byte[] digest = md.digest(input); // Create a digest info consisting of the algorithm id and the hash final AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, DERNull.INSTANCE); final DigestInfo digestInfo = new DigestInfo(algId, digest); final byte[] message = digestInfo.getEncoded(ASN1Encoding.DER); // Do PKCS1 padding final byte[] block = new byte[((modulus.bitLength() + 7) / 8) - 1]; System.arraycopy(message, 0, block, block.length - message.length, message.length); block[0] = 0x01; // type code 1 for (int i = 1; i != block.length - message.length - 1; i++) { block[i] = (byte) 0xFF; } return new BigInteger(1, block); }
Example 3
Source File: ScepUtil.java From xipki with Apache License 2.0 | 5 votes |
public static ASN1ObjectIdentifier extractDigesetAlgorithmIdentifier(String sigOid, byte[] sigParams) throws NoSuchAlgorithmException { Args.notBlank(sigOid, "sigOid"); ASN1ObjectIdentifier algOid = new ASN1ObjectIdentifier(sigOid); ASN1ObjectIdentifier digestAlgOid; if (PKCSObjectIdentifiers.md5WithRSAEncryption.equals(algOid)) { digestAlgOid = PKCSObjectIdentifiers.md5; } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) { digestAlgOid = X509ObjectIdentifiers.id_SHA1; } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha224; } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha256; } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha384; } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha512; } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigParams); digestAlgOid = param.getHashAlgorithm().getAlgorithm(); } else { throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId()); } return digestAlgOid; }
Example 4
Source File: RequestOptions.java From xipki with Apache License 2.0 | 4 votes |
private static AlgorithmIdentifier createAlgId(String algoName) { algoName = algoName.toUpperCase(); ASN1ObjectIdentifier algOid = null; if ("SHA1WITHRSA".equals(algoName)) { algOid = PKCSObjectIdentifiers.sha1WithRSAEncryption; } else if ("SHA256WITHRSA".equals(algoName)) { algOid = PKCSObjectIdentifiers.sha256WithRSAEncryption; } else if ("SHA384WITHRSA".equals(algoName)) { algOid = PKCSObjectIdentifiers.sha384WithRSAEncryption; } else if ("SHA512WITHRSA".equals(algoName)) { algOid = PKCSObjectIdentifiers.sha512WithRSAEncryption; } else if ("SHA1WITHECDSA".equals(algoName)) { algOid = X9ObjectIdentifiers.ecdsa_with_SHA1; } else if ("SHA256WITHECDSA".equals(algoName)) { algOid = X9ObjectIdentifiers.ecdsa_with_SHA256; } else if ("SHA384WITHECDSA".equals(algoName)) { algOid = X9ObjectIdentifiers.ecdsa_with_SHA384; } else if ("SHA512WITHECDSA".equals(algoName)) { algOid = X9ObjectIdentifiers.ecdsa_with_SHA512; } else if ("SHA1WITHRSAANDMGF1".equals(algoName) || "SHA256WITHRSAANDMGF1".equals(algoName) || "SHA384WITHRSAANDMGF1".equals(algoName) || "SHA512WITHRSAANDMGF1".equals(algoName)) { algOid = PKCSObjectIdentifiers.id_RSASSA_PSS; } else { throw new IllegalStateException("Unsupported algorithm " + algoName); // should not happen } ASN1Encodable params; if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { ASN1ObjectIdentifier digestAlgOid = null; if ("SHA1WITHRSAANDMGF1".equals(algoName)) { digestAlgOid = X509ObjectIdentifiers.id_SHA1; } else if ("SHA256WITHRSAANDMGF1".equals(algoName)) { digestAlgOid = NISTObjectIdentifiers.id_sha256; } else if ("SHA384WITHRSAANDMGF1".equals(algoName)) { digestAlgOid = NISTObjectIdentifiers.id_sha384; } else { // if ("SHA512WITHRSAANDMGF1".equals(algoName)) digestAlgOid = NISTObjectIdentifiers.id_sha512; } params = createPSSRSAParams(digestAlgOid); } else { params = DERNull.INSTANCE; } return new AlgorithmIdentifier(algOid, params); }