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);
}
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();
}
}
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;
}
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");
}
}
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();
}
}
Aggregations