Search in sources :

Example 6 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project j2objc by google.

the class KeyIdentifier method toString.

/**
     * Returns a printable representation of the KeyUsage.
     */
public String toString() {
    String s = "KeyIdentifier [\n";
    HexDumpEncoder encoder = new HexDumpEncoder();
    s += encoder.encodeBuffer(octetString);
    s += "]\n";
    return (s);
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 7 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project j2objc by google.

the class PKCS9Attribute method toString.

/**
     * Returns a string representation of this attribute.
     */
public String toString() {
    StringBuffer buf = new StringBuffer(100);
    buf.append("[");
    if (index == -1) {
        buf.append(oid.toString());
    } else {
        buf.append(OID_NAME_TABLE.get(PKCS9_OIDS[index]));
    }
    buf.append(": ");
    if (index == -1 || SINGLE_VALUED[index]) {
        if (value instanceof byte[]) {
            // special case for octet string
            HexDumpEncoder hexDump = new HexDumpEncoder();
            buf.append(hexDump.encodeBuffer((byte[]) value));
        } else {
            buf.append(value.toString());
        }
        buf.append("]");
        return buf.toString();
    } else {
        // multi-valued
        boolean first = true;
        Object[] values = (Object[]) value;
        for (int j = 0; j < values.length; j++) {
            if (first)
                first = false;
            else
                buf.append(", ");
            buf.append(values[j].toString());
        }
        return buf.toString();
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 8 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project j2objc by google.

the class SignerInfo method toString.

public String toString() {
    HexDumpEncoder hexDump = new HexDumpEncoder();
    String out = "";
    out += "Signer Info for (issuer): " + issuerName + "\n";
    out += "\tversion: " + Debug.toHexString(version) + "\n";
    out += "\tcertificateSerialNumber: " + Debug.toHexString(certificateSerialNumber) + "\n";
    out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n";
    if (authenticatedAttributes != null) {
        out += "\tauthenticatedAttributes: " + authenticatedAttributes + "\n";
    }
    out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId + "\n";
    out += "\tencryptedDigest: " + "\n" + hexDump.encodeBuffer(encryptedDigest) + "\n";
    if (unauthenticatedAttributes != null) {
        out += "\tunauthenticatedAttributes: " + unauthenticatedAttributes + "\n";
    }
    return out;
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 9 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class PublicKeyInterop method main.

public static void main(String[] arg) throws Exception {
    KeyStore ks = KeyStore.getInstance("Windows-MY");
    ks.load(null, null);
    System.out.println("Loaded keystore: Windows-MY");
    PublicKey myPuKey = (PublicKey) ks.getCertificate("6888925").getPublicKey();
    System.out.println("Public key is a " + myPuKey.getClass().getName());
    PrivateKey myPrKey = (PrivateKey) ks.getKey("6888925", null);
    System.out.println("Private key is a " + myPrKey.getClass().getName());
    System.out.println();
    byte[] plain = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
    HexDumpEncoder hde = new HexDumpEncoder();
    System.out.println("Plaintext:\n" + hde.encode(plain) + "\n");
    Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    rsa.init(Cipher.ENCRYPT_MODE, myPuKey);
    byte[] encrypted = rsa.doFinal(plain);
    System.out.println("Encrypted plaintext using RSA Cipher from " + rsa.getProvider().getName() + " JCE provider\n");
    System.out.println(hde.encode(encrypted) + "\n");
    Cipher rsa2 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
    rsa2.init(Cipher.ENCRYPT_MODE, myPuKey);
    byte[] encrypted2 = rsa2.doFinal(plain);
    System.out.println("Encrypted plaintext using RSA Cipher from " + rsa2.getProvider().getName() + " JCE provider\n");
    System.out.println(hde.encode(encrypted2) + "\n");
    Cipher rsa3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
    rsa3.init(Cipher.DECRYPT_MODE, myPrKey);
    byte[] decrypted = rsa3.doFinal(encrypted);
    System.out.println("Decrypted first ciphertext using RSA Cipher from " + rsa3.getProvider().getName() + " JCE provider\n");
    System.out.println(hde.encode(decrypted) + "\n");
    if (!Arrays.equals(plain, decrypted)) {
        throw new Exception("First decrypted ciphertext does not match " + "original plaintext");
    }
    decrypted = rsa3.doFinal(encrypted2);
    System.out.println("Decrypted second ciphertext using RSA Cipher from " + rsa3.getProvider().getName() + " JCE provider\n");
    System.out.println(hde.encode(decrypted) + "\n");
    if (!Arrays.equals(plain, decrypted)) {
        throw new Exception("Second decrypted ciphertext does not match " + "original plaintext");
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 10 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class PKCS9Attribute method toString.

/**
     * Returns a string representation of this attribute.
     */
public String toString() {
    StringBuffer buf = new StringBuffer(100);
    buf.append("[");
    if (index == -1) {
        buf.append(oid.toString());
    } else {
        buf.append(OID_NAME_TABLE.get(PKCS9_OIDS[index]));
    }
    buf.append(": ");
    if (index == -1 || SINGLE_VALUED[index]) {
        if (value instanceof byte[]) {
            // special case for octet string
            HexDumpEncoder hexDump = new HexDumpEncoder();
            buf.append(hexDump.encodeBuffer((byte[]) value));
        } else {
            buf.append(value.toString());
        }
        buf.append("]");
        return buf.toString();
    } else {
        // multi-valued
        boolean first = true;
        Object[] values = (Object[]) value;
        for (int j = 0; j < values.length; j++) {
            if (first)
                first = false;
            else
                buf.append(", ");
            buf.append(values[j].toString());
        }
        return buf.toString();
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Aggregations

HexDumpEncoder (sun.misc.HexDumpEncoder)51 IOException (java.io.IOException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)6 CRLException (java.security.cert.CRLException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 NamingException (javax.naming.NamingException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 SignatureException (java.security.SignatureException)2 X509CRLEntry (java.security.cert.X509CRLEntry)2 PRF (sun.security.ssl.CipherSuite.PRF)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Constructor (java.lang.reflect.Constructor)1 ByteBuffer (java.nio.ByteBuffer)1 AccessControlContext (java.security.AccessControlContext)1 GeneralSecurityException (java.security.GeneralSecurityException)1 PrivilegedActionException (java.security.PrivilegedActionException)1