本文整理汇总了Java中org.apache.harmony.security.x509.GeneralNames.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java GeneralNames.getEncoded方法的具体用法?Java GeneralNames.getEncoded怎么用?Java GeneralNames.getEncoded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.harmony.security.x509.GeneralNames
的用法示例。
在下文中一共展示了GeneralNames.getEncoded方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCertEncoding
import org.apache.harmony.security.x509.GeneralNames; //导入方法依赖的package包/类
/**
* Constructs the encoded form of certificate with specified subject field
* of TBSCertificate and specified alternative names.
*/
private byte[] getCertEncoding(Name subject, GeneralNames subjectAltNames)
throws IOException {
// make the TBSCertificate for Certificate
int version = 2; //v3
BigInteger serialNumber = BigInteger.valueOf(555L);
AlgorithmIdentifier signature = new AlgorithmIdentifier("1.2.3.44.555");
Name issuer = new Name("O=Certificate Issuer");
Validity validity = new Validity(new Date(100000000),
new Date(200000000));
SubjectPublicKeyInfo subjectPublicKeyInfo =
new SubjectPublicKeyInfo(
new AlgorithmIdentifier("1.2.840.113549.1.1.2"),
new byte[10]);
boolean[] issuerUniqueID = new boolean[]
{true, false, true, false, true, false, true, false};
boolean[] subjectUniqueID = new boolean[]
{false, true, false, true, false, true, false, true};
Extension extension = new Extension("2.5.29.17",
true, subjectAltNames.getEncoded());
Extensions extensions = new Extensions();
extensions.addExtension(extension);
TBSCertificate tbsCertificate = new TBSCertificate(version,
serialNumber, signature, issuer, validity, subject,
subjectPublicKeyInfo, issuerUniqueID, subjectUniqueID,
extensions);
// make the Certificate
org.apache.harmony.security.x509.Certificate certificate =
new org.apache.harmony.security.x509.Certificate
(tbsCertificate, signature, new byte[10]);
return certificate.getEncoded();
}
示例2: _testEDIPartyName1
import org.apache.harmony.security.x509.GeneralNames; //导入方法依赖的package包/类
/**
* EDIPartyName(String nameAssigner, String partyName) method testing.
*/
public void _testEDIPartyName1() {
boolean pass = true;
EDIPartyName ediPN = new EDIPartyName("nameAssigner", "partyName");
byte[] encoded = ediPN.getEncoded();
// manually derived data:
byte[] _encoded = {
(byte) 0x30, (byte) 0x1d, (byte) 0x80, (byte) 0x0e,
(byte) 0x13, (byte) 0x0c, (byte) 0x6e, (byte) 0x61,
(byte) 0x6d, (byte) 0x65, (byte) 0x41, (byte) 0x73,
(byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e,
(byte) 0x65, (byte) 0x72, (byte) 0x81, (byte) 0x0b,
(byte) 0x13, (byte) 0x09, (byte) 0x70, (byte) 0x61,
(byte) 0x72, (byte) 0x74, (byte) 0x79, (byte) 0x4e,
(byte) 0x61, (byte) 0x6d, (byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of EDIPartyName is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
GeneralName gName = new GeneralName(ediPN);
encoded = gName.getEncoded();
// manually derived data:
_encoded = new byte[] {
(byte) 0xa5, (byte) 0x1d, (byte) 0x80, (byte) 0x0e,
(byte) 0x13, (byte) 0x0c, (byte) 0x6e, (byte) 0x61,
(byte) 0x6d, (byte) 0x65, (byte) 0x41, (byte) 0x73,
(byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e,
(byte) 0x65, (byte) 0x72, (byte) 0x81, (byte) 0x0b,
(byte) 0x13, (byte) 0x09, (byte) 0x70, (byte) 0x61,
(byte) 0x72, (byte) 0x74, (byte) 0x79, (byte) 0x4e,
(byte) 0x61, (byte) 0x6d, (byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of GeneralName is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
GeneralNames gNames = new GeneralNames();
gNames.addName(gName);
encoded = gNames.getEncoded();
// manually derived data:
_encoded = new byte[] {
(byte) 0x30, (byte) 0x1f, (byte) 0xa5, (byte) 0x1d,
(byte) 0x80, (byte) 0x0e, (byte) 0x13, (byte) 0x0c,
(byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65,
(byte) 0x41, (byte) 0x73, (byte) 0x73, (byte) 0x69,
(byte) 0x67, (byte) 0x6e, (byte) 0x65, (byte) 0x72,
(byte) 0x81, (byte) 0x0b, (byte) 0x13, (byte) 0x09,
(byte) 0x70, (byte) 0x61, (byte) 0x72, (byte) 0x74,
(byte) 0x79, (byte) 0x4e, (byte) 0x61, (byte) 0x6d,
(byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of GeneralNames is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
assertTrue("Some problems occured.", pass);
}
示例3: testCertificate
import org.apache.harmony.security.x509.GeneralNames; //导入方法依赖的package包/类
/**
* Certificate(TBSCertificate tbsCertificate, AlgorithmIdentifier
* signatureAlgorithm, byte[] signatureValue) method testing.
* Makes the certificate, gets its encoded form, makes new certificate
* from this encoded form by CertificateFactory, and decodes encoded
* form.
*/
public void testCertificate() throws Exception {
// make the TBSCertificate for Certificate
int version = 2; //v3
BigInteger serialNumber = BigInteger.valueOf(555L);
AlgorithmIdentifier signature = new AlgorithmIdentifier("1.2.3.44.555"); // random value
Name issuer = new Name("O=Certificate Issuer");
Validity validity = new Validity(new Date(100000000), new Date(200000000));
Name subject = new Name("O=Subject Organization");
SubjectPublicKeyInfo subjectPublicKeyInfo =
new SubjectPublicKeyInfo(new AlgorithmIdentifier("1.2.840.113549.1.1.2"),
new byte[10]);
boolean[] issuerUniqueID = new boolean[]
{true, false, true, false, true, false, true, false}; // random value
boolean[] subjectUniqueID = new boolean[]
{false, true, false, true, false, true, false, true}; // random value
// make the Extensions for TBSCertificate
// Subject Alternative Names
GeneralName[] san = new GeneralName[] {
new GeneralName(
new OtherName("1.2.3.4.5",
ASN1Integer.getInstance().encode(
BigInteger.valueOf(55L).toByteArray()))),
new GeneralName(1, "[email protected]"),
new GeneralName(2, "dNSName"),
new GeneralName(new ORAddress()),
new GeneralName(4, "O=Organization"),
new GeneralName(new EDIPartyName("assigner","party")),
new GeneralName(6, "http://Resource.Id"),
new GeneralName(new byte[] {1, 1, 1, 1}),
new GeneralName(8, "1.2.3.4444.55555")
};
GeneralNames sans = new GeneralNames(Arrays.asList(san));
Extension extension = new Extension("2.5.29.17", true, sans.getEncoded());
Extensions extensions = new Extensions();
extensions.addExtension(extension);
byte[] encoding = extensions.getEncoded();
Extensions.ASN1.decode(encoding);
TBSCertificate tbsCertificate = new TBSCertificate(version, serialNumber,
signature, issuer, validity, subject, subjectPublicKeyInfo,
issuerUniqueID, subjectUniqueID, extensions);
encoding = tbsCertificate.getEncoded();
TBSCertificate.ASN1.decode(encoding);
Certificate certificate = new Certificate(tbsCertificate, signature, new byte[10]);
encoding = certificate.getEncoded();
Certificate.ASN1.decode(encoding);
encoding = Certificate.ASN1.encode(certificate);
ByteArrayInputStream bais = new ByteArrayInputStream(encoding);
//try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
cf.generateCertificate(bais);
//} catch (CertificateException e) {
// there is no X.509 certificate factory implementation installed
//}
}
示例4: _testEDIPartyName1
import org.apache.harmony.security.x509.GeneralNames; //导入方法依赖的package包/类
/**
* EDIPartyName(String nameAssigner, String partyName) method testing.
*/
public void _testEDIPartyName1() {
boolean pass = true;
try {
EDIPartyName ediPN = new EDIPartyName("nameAssigner", "partyName");
byte[] encoded = ediPN.getEncoded();
// manually derived data:
byte[] _encoded = {
(byte) 0x30, (byte) 0x1d, (byte) 0x80, (byte) 0x0e,
(byte) 0x13, (byte) 0x0c, (byte) 0x6e, (byte) 0x61,
(byte) 0x6d, (byte) 0x65, (byte) 0x41, (byte) 0x73,
(byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e,
(byte) 0x65, (byte) 0x72, (byte) 0x81, (byte) 0x0b,
(byte) 0x13, (byte) 0x09, (byte) 0x70, (byte) 0x61,
(byte) 0x72, (byte) 0x74, (byte) 0x79, (byte) 0x4e,
(byte) 0x61, (byte) 0x6d, (byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of EDIPartyName is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
GeneralName gName = new GeneralName(ediPN);
encoded = gName.getEncoded();
// manually derived data:
_encoded = new byte[] {
(byte) 0xa5, (byte) 0x1d, (byte) 0x80, (byte) 0x0e,
(byte) 0x13, (byte) 0x0c, (byte) 0x6e, (byte) 0x61,
(byte) 0x6d, (byte) 0x65, (byte) 0x41, (byte) 0x73,
(byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e,
(byte) 0x65, (byte) 0x72, (byte) 0x81, (byte) 0x0b,
(byte) 0x13, (byte) 0x09, (byte) 0x70, (byte) 0x61,
(byte) 0x72, (byte) 0x74, (byte) 0x79, (byte) 0x4e,
(byte) 0x61, (byte) 0x6d, (byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of GeneralName is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
GeneralNames gNames = new GeneralNames();
gNames.addName(gName);
encoded = gNames.getEncoded();
// manually derived data:
_encoded = new byte[] {
(byte) 0x30, (byte) 0x1f, (byte) 0xa5, (byte) 0x1d,
(byte) 0x80, (byte) 0x0e, (byte) 0x13, (byte) 0x0c,
(byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65,
(byte) 0x41, (byte) 0x73, (byte) 0x73, (byte) 0x69,
(byte) 0x67, (byte) 0x6e, (byte) 0x65, (byte) 0x72,
(byte) 0x81, (byte) 0x0b, (byte) 0x13, (byte) 0x09,
(byte) 0x70, (byte) 0x61, (byte) 0x72, (byte) 0x74,
(byte) 0x79, (byte) 0x4e, (byte) 0x61, (byte) 0x6d,
(byte) 0x65
};
if (!Arrays.equals(encoded, _encoded)) {
System.out.println("Got encoded form of GeneralNames is:");
printAsHex(16, "", " ", encoded);
System.out.println("But should be like this:");
printAsHex(16, "", " ", _encoded);
System.out.println("");
pass = false;
}
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected Exception was thrown.");
}
assertTrue("Some problems occured.", pass);
}