本文整理了Java中org.bouncycastle.asn1.ASN1Sequence.getEncoded()
方法的一些代码示例,展示了ASN1Sequence.getEncoded()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ASN1Sequence.getEncoded()
方法的具体详情如下:
包路径:org.bouncycastle.asn1.ASN1Sequence
类名称:ASN1Sequence
方法名:getEncoded
暂无
代码示例来源:origin: arhs/sd-dss
public static byte[] getEncoded(final ASN1Sequence signPolicyInfo) throws DSSException {
try {
return signPolicyInfo.getEncoded(ASN1Encoding.DER);
} catch (IOException e) {
throw new DSSException(e);
}
}
代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on
private X509AttributeCertificate readPEMCertificate(
InputStream in)
throws IOException
{
ASN1Sequence seq = PEM_PARSER.readPEMObject(in);
if (seq != null)
{
return new X509V2AttributeCertificate(seq.getEncoded());
}
return null;
}
代码示例来源:origin: kaikramer/keystore-explorer
private byte[] createPublicKeyAndChallengeForSigning() throws SpkacException {
try {
return new DERBitString(createPublicKeyAndChallenge().getEncoded(ASN1Encoding.DER)).getBytes();
} catch (Exception ex) {
throw new SpkacException(res.getString("NoGetPublicKeyAndChallengeForSignature.exception.message"), ex);
}
}
代码示例来源:origin: stackoverflow.com
@Test
public void testKey() throws Exception {
String privKeyStr = "MIICXQIBAAKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L+CDQEPLYakoem+jFnUKDH5+pru/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQABAoGANOFrYBqK5lvu1koOswDWQZFZqcSSzh8IZyoGwGWa7S0r0EECXlDXmuPSq8e9IfRG8ALHrH+ZlrbnFOSgyVSWHfpj3aH+qknoSX5TW2rMQHih8865xuqheMQ+RTZ7+BRDqNsYkzxB/Z8mqzpoJQSYf+H7nWxdDCgAJVYZzxl3DmUCQQD32iEjnwiwUjii8slcmvCEZl+z84DWNdvJOg6Z38sI4AvrfpKc1WAcDg1rNZCKrRgokh54wpLt08cpFcrD04c3AkEAiTzDmc0bdgfg5wj6xHFZpYlBwiGm/bjOR2PS57P0GNU5PsDllRbFqIuzArITutO5lvZZImzuYz7Lf+cQ73pxUwJBAOdEwmdaneDo17A0m2+to3/nhqWDMVSwLMU3RyiNigZeCMFU+bkd4PBMrHi9IoJDwacZsRU9eZwxYEUV8H2Jg0ECQEEkOqRSm2pXKwX/WSjNtQPCNxhy6NUeV6vDUmTxIjh3XYjP/ynZeVEbnoj1BjB0N2/U11Jj6nPpZqb7gyppMEkCQQCoGdVYDipU+hMMnvxa0zOIyQc/a+HE0lESqn+2ZPafYi9Z1RldRMvUXhP8U7s+OuhRwprdw2ivvOFrnWyz9lL2";
byte[] data = Base64.getDecoder().decode(privKeyStr);
/* Add PKCS#8 formatting */
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(0));
ASN1EncodableVector v2 = new ASN1EncodableVector();
v2.add(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.rsaEncryption.getId()));
v2.add(DERNull.INSTANCE);
v.add(new DERSequence(v2));
v.add(new DEROctetString(data));
ASN1Sequence seq = new DERSequence(v);
byte[] privKey = seq.getEncoded("DER");
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(privKey);
KeyFactory fact = KeyFactory.getInstance("RSA");
PrivateKey key = fact.generatePrivate(spec);
Assert.assertNotNull("Failed to generate the private key", key);
}
代码示例来源:origin: ontio/ontology-java-sdk
private byte[] DSADERtoPlain(byte[] sig) throws IOException {
ASN1Sequence seq = (ASN1Sequence) ASN1Primitive.fromByteArray(sig);
if (seq.size() != 2) {
throw new IOException(ErrorCode.MalformedSignature);
} else if (!Arrays.equals(sig, seq.getEncoded("DER"))) {
throw new IOException(ErrorCode.MalformedSignature);
}
byte[] r = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().toByteArray();
byte[] s = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().toByteArray();
int ri = (r[0] == 0) ? 1 : 0;
int rl = r.length - ri;
int si = (s[0] == 0) ? 1 : 0;
int sl = s.length - si;
byte[] res;
if (rl > sl) {
res = new byte[rl * 2];
} else {
res = new byte[sl * 2];
}
System.arraycopy(r, ri, res, res.length/2 - rl, rl);
System.arraycopy(s, si, res, res.length-sl, sl);
return res;
}
代码示例来源:origin: ontio/ontology-java-sdk
private byte[] DSADERtoPlain(byte[] sig) throws IOException {
ASN1Sequence seq = (ASN1Sequence) ASN1Primitive.fromByteArray(sig);
if (seq.size() != 2) {
throw new IOException(ErrorCode.MalformedSignature);
} else if (!Arrays.equals(sig, seq.getEncoded("DER"))) {
throw new IOException(ErrorCode.MalformedSignature);
}
byte[] r = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().toByteArray();
byte[] s = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().toByteArray();
int ri = (r[0] == 0) ? 1 : 0;
int rl = r.length - ri;
int si = (s[0] == 0) ? 1 : 0;
int sl = s.length - si;
byte[] res;
if (rl > sl) {
res = new byte[rl * 2];
} else {
res = new byte[sl * 2];
}
System.arraycopy(r, ri, res, res.length/2 - rl, rl);
System.arraycopy(s, si, res, res.length-sl, sl);
return res;
}
代码示例来源:origin: org.xipki/security
public static Extension createExtnSubjectInfoAccess(List<String> accessMethodAndLocations,
boolean critical) throws BadInputException {
if (CollectionUtil.isEmpty(accessMethodAndLocations)) {
return null;
}
ASN1EncodableVector vector = new ASN1EncodableVector();
for (String accessMethodAndLocation : accessMethodAndLocations) {
vector.add(createAccessDescription(accessMethodAndLocation));
}
ASN1Sequence seq = new DERSequence(vector);
try {
return new Extension(Extension.subjectInfoAccess, critical, seq.getEncoded());
} catch (IOException ex) {
throw new IllegalStateException(ex.getMessage(), ex);
}
}
代码示例来源:origin: org.xipki.tk/security
public static Extension createExtensionSubjectInfoAccess(
final List<String> accessMethodAndLocations, final boolean critical)
throws BadInputException {
if (CollectionUtil.isEmpty(accessMethodAndLocations)) {
return null;
}
ASN1EncodableVector vector = new ASN1EncodableVector();
for (String accessMethodAndLocation : accessMethodAndLocations) {
vector.add(createAccessDescription(accessMethodAndLocation));
}
ASN1Sequence seq = new DERSequence(vector);
try {
return new Extension(Extension.subjectInfoAccess, critical, seq.getEncoded());
} catch (IOException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
代码示例来源:origin: SAMLRaider/SAMLRaider
public String getAuthorityKeyIdentifier() {
byte[] e = certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId());
if (e == null) {
return "";
}
ASN1Primitive ap;
byte[] k = {};
try {
ap = JcaX509ExtensionUtils.parseExtensionValue(e);
k = ASN1Sequence.getInstance(ap.getEncoded()).getEncoded();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Very ugly hack to extract the SHA1 Hash (59 Hex Chars) from the
// Extension :(
return CertificateHelper.addHexColons(CertificateHelper.byteArrayToHex(k)).substring(12, k.length * 3 - 1);
}
代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on
private X509AttributeCertificate getCertificate()
throws IOException
{
if (sData != null)
{
while (sDataObjectCount < sData.size())
{
Object obj = sData.getObjectAt(sDataObjectCount++);
if (obj instanceof ASN1TaggedObject && ((ASN1TaggedObject)obj).getTagNo() == 2)
{
return new X509V2AttributeCertificate(
ASN1Sequence.getInstance((ASN1TaggedObject)obj, false).getEncoded());
}
}
}
return null;
}
代码示例来源:origin: aws/aws-encryption-sdk-java
private byte[] generateEcdsaFixedLengthSignature(final byte[] digest) throws SignatureException {
byte[] signature;
// Unfortunately, we need deterministic lengths some signatures are non-deterministic in length.
// So, retry until we get the right length :-(
do {
trailingSig_.update(digest);
signature = trailingSig_.sign();
if (signature.length != cryptoAlgo_.getTrailingSignatureLength()) {
// Most of the time, a signature of the wrong length can be fixed
// be negating s in the signature relative to the group order.
ASN1Sequence seq = ASN1Sequence.getInstance(signature);
ASN1Integer r = (ASN1Integer) seq.getObjectAt(0);
ASN1Integer s = (ASN1Integer) seq.getObjectAt(1);
ECPrivateKey ecKey = (ECPrivateKey) trailingSignaturePrivateKey_;
s = new ASN1Integer(ecKey.getParams().getOrder().subtract(s.getPositiveValue()));
seq = new DERSequence(new ASN1Encodable[]{r, s});
try {
signature = seq.getEncoded();
} catch (IOException ex) {
throw new SignatureException(ex);
}
}
} while (signature.length != cryptoAlgo_.getTrailingSignatureLength());
return signature;
}
代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on
private X509AttributeCertificate readDERCertificate(
InputStream in)
throws IOException
{
ASN1InputStream dIn = new ASN1InputStream(in);
ASN1Sequence seq = (ASN1Sequence)dIn.readObject();
if (seq.size() > 1
&& seq.getObjectAt(0) instanceof ASN1ObjectIdentifier)
{
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData))
{
sData = new SignedData(ASN1Sequence.getInstance(
(ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates();
return getCertificate();
}
}
return new X509V2AttributeCertificate(seq.getEncoded());
}
代码示例来源:origin: kaikramer/keystore-explorer
/**
* Output SPKAC.
*
* @param os
* Output stream
* @throws IOException
* If an I/O problem occurs
* @throws SpkacException
* If output fails
*/
public void output(OutputStream os) throws IOException, SpkacException {
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(os);
outputProperty(osw, SPKAC_PROPERTY,
new String(Base64.encode(createSignedPublicKeyAndChallenge().getEncoded(ASN1Encoding.DER))));
outputProperty(osw, CN_PROPERTY, subject.getCN());
outputProperty(osw, OU_PROPERTY, subject.getOU());
outputProperty(osw, O_PROPERTY, subject.getO());
outputProperty(osw, L_PROPERTY, subject.getL());
outputProperty(osw, ST_PROPERTY, subject.getST());
outputProperty(osw, C_PROPERTY, subject.getC());
} catch (IOException ex) {
throw new SpkacException(res.getString("NoOutputSpkac.exception.message"), ex);
} finally {
IOUtils.closeQuietly(osw);
}
}
代码示例来源:origin: org.xipki.shells/security-shell
extensions.add(new Extension(extType, false, extValue.getEncoded()));
needExtensionTypes.add(extType.getId());
extensions.add(new Extension(extType, false, extValue.getEncoded()));
needExtensionTypes.add(extType.getId());
} else if (biometricType == null && biometricHashAlgo == null && biometricFile == null) {
代码示例来源:origin: esig/dss
infos.setIssuer(new X500Principal(sequence.getEncoded()));
内容来源于网络,如有侵权,请联系作者删除!