本文整理汇总了Java中javax.security.auth.x500.X500Principal.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java X500Principal.getEncoded方法的具体用法?Java X500Principal.getEncoded怎么用?Java X500Principal.getEncoded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.x500.X500Principal
的用法示例。
在下文中一共展示了X500Principal.getEncoded方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSubjectX500Name
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
/**
* Return the subject of a certificate as X500Name, by reparsing if
* necessary. X500Name should only be used if access to name components
* is required, in other cases X500Principal is to be preferred.
*
* This method is currently used from within JSSE, do not remove.
*/
public static X500Name getSubjectX500Name(X509Certificate cert)
throws CertificateParsingException {
try {
Principal subjectDN = cert.getSubjectDN();
if (subjectDN instanceof X500Name) {
return (X500Name)subjectDN;
} else {
X500Principal subjectX500 = cert.getSubjectX500Principal();
return new X500Name(subjectX500.getEncoded());
}
} catch (IOException e) {
throw(CertificateParsingException)
new CertificateParsingException().initCause(e);
}
}
示例2: convertPrincipal
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
static X509Principal convertPrincipal(
X500Principal principal)
{
try
{
return new X509Principal(principal.getEncoded());
}
catch (IOException e)
{
throw new IllegalArgumentException("cannot convert principal");
}
}
示例3: convertName
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
private static X509Name convertName(
X500Principal name)
{
try
{
return new X509Principal(name.getEncoded());
}
catch (IOException e)
{
throw new IllegalArgumentException("can't convert name");
}
}
示例4: setRequestorName
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
/**
* Set the requestor name to the passed in X500Principal
*
* @param requestorName a X500Principal representing the requestor name.
*/
public void setRequestorName(
X500Principal requestorName)
{
try
{
this.requestorName = new GeneralName(GeneralName.directoryName, new X509Principal(requestorName.getEncoded()));
}
catch (IOException e)
{
throw new IllegalArgumentException("cannot encode principal: " + e);
}
}
示例5: getCertificateFriendlyName
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
public static String getCertificateFriendlyName(X509Certificate cert) {
X500Principal principal = cert.getSubjectX500Principal();
byte[] encodedSubject = principal.getEncoded();
String friendlyName = null;
/* Hack so we do not have to ship a whole Spongy/bouncycastle */
Exception exp = null;
try {
Class X509NameClass = Class.forName("com.android.org.bouncycastle.asn1.x509.X509Name");
Method getInstance = X509NameClass.getMethod("getInstance", Object.class);
Hashtable defaultSymbols = (Hashtable) X509NameClass.getField("DefaultSymbols").get(X509NameClass);
if (!defaultSymbols.containsKey("1.2.840.113549.1.9.1")) defaultSymbols.put("1.2.840.113549.1.9.1", "eMail");
Object subjectName = getInstance.invoke(X509NameClass, encodedSubject);
Method toString = X509NameClass.getMethod("toString", boolean.class, Hashtable.class);
friendlyName = (String) toString.invoke(subjectName, true, defaultSymbols);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | NoSuchFieldException e) {
exp = e;
}
if (exp != null) VpnStatus.logException("Getting X509 Name from certificate", exp);
/* Fallback if the reflection method did not work */
if (friendlyName == null) friendlyName = principal.getName();
// Really evil hack to decode email address
// See: http://code.google.com/p/android/issues/detail?id=21531
String[] parts = friendlyName.split(",");
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (part.startsWith("1.2.840.113549.1.9.1=#16")) {
parts[i] = "email=" + ia5decode(part.replace("1.2.840.113549.1.9.1=#16", ""));
}
}
friendlyName = TextUtils.join(",", parts);
return friendlyName;
}
示例6: getEncoded
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
/** {@inheritDoc} */
public byte[] getEncoded(X500Principal principal) {
if (principal == null) {
throw new NullPointerException("X500Principal may not be null");
}
return principal.getEncoded();
}
示例7: AttributeCertificateIssuer
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
public AttributeCertificateIssuer(X500Principal principal)
throws IOException
{
this(new X509Principal(principal.getEncoded()));
}
示例8: DistinguishedName
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
DistinguishedName(X500Principal dn) {
name = dn.getEncoded();
}
示例9: testDN
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
private static void testDN(String dn) throws Exception {
X500Principal p = new X500Principal(dn);
byte[] encoded = p.getEncoded();
// name is a sequence of RDN's
DerInputStream dis = new DerInputStream(encoded);
DerValue[] nameseq = dis.getSequence(3);
boolean passed = false;
for (int i = 0; i < nameseq.length; i++) {
// each RDN is a set of AttributeTypeAndValue
DerInputStream is = new DerInputStream(nameseq[i].toByteArray());
DerValue[] ava = is.getSet(3);
for (int j = 0; j < ava.length; j++) {
ObjectIdentifier oid = ava[j].data.getOID();
if (oid.equals(X500Name.DOMAIN_COMPONENT_OID)) {
DerValue value = ava[j].data.getDerValue();
if (value.getTag() == DerValue.tag_IA5String) {
passed = true;
break;
} else {
throw new SecurityException
("Test failed, expected DOMAIN_COMPONENT tag '" +
DerValue.tag_IA5String +
"', got '" +
value.getTag() + "'");
}
}
}
if (passed) {
break;
}
}
if (passed) {
System.out.println("Test passed");
} else {
throw new SecurityException("Test failed");
}
}
示例10: main
import javax.security.auth.x500.X500Principal; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
// create 2 different X500Principals
X500Principal p = new X500Principal("o=sun, cn=duke");
X500Principal p2 = new X500Principal("o=sun, cn=dukette");
// get the encoded bytes for the 2 principals
byte[] encoded = p.getEncoded();
byte[] encoded2 = p2.getEncoded();
// create a ByteArrayInputStream with the
// encodings from the 2 principals
byte[] all = new byte[encoded.length + encoded2.length];
System.arraycopy(encoded, 0, all, 0, encoded.length);
System.arraycopy(encoded2, 0, all, encoded.length, encoded2.length);
ByteArrayInputStream bais = new ByteArrayInputStream(all);
// create 2 new X500Principals from the ByteArrayInputStream
X500Principal pp = new X500Principal(bais);
X500Principal pp2 = new X500Principal(bais);
// sanity check the 2 new principals
if (p.equals(pp) && p2.equals(pp2) && !pp.equals(pp2)) {
System.out.println("Test 1 passed");
} else {
throw new SecurityException("Test 1 failed");
}
// corrupt the ByteArrayInputStream and see if the
// mark/reset worked
byte[] all2 = new byte[all.length];
System.arraycopy(all, 0, all2, 0, all.length);
all2[encoded.length + 2] = (byte)-1;
bais = new ByteArrayInputStream(all2);
// this should work
X500Principal ppp = new X500Principal(bais);
// this should throw an IOException due to stream corruption
int origAvailable = bais.available();
try {
X500Principal ppp2 = new X500Principal(bais);
throw new SecurityException("Test 2 (part a) failed");
} catch (IllegalArgumentException iae) {
if (bais.available() == origAvailable) {
System.out.println("Test 2 passed");
} else {
throw new SecurityException("Test 2 (part b) failed");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new SecurityException(e.getMessage());
}
}