< prev index next > src/java.base/share/classes/sun/security/tools/keytool/Main.java
Print this page
new CertificateAlgorithmId(algID));
info.set(X509CertInfo.ISSUER, issuer);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
boolean canRead = false;
! StringBuffer sb = new StringBuffer();
while (true) {
String s = reader.readLine();
if (s == null) break;
// OpenSSL does not use NEW
//if (s.startsWith("-----BEGIN NEW CERTIFICATE REQUEST-----")) {
new CertificateAlgorithmId(algID));
info.set(X509CertInfo.ISSUER, issuer);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
boolean canRead = false;
! StringBuilder sb = new StringBuilder();
while (true) {
String s = reader.readLine();
if (s == null) break;
// OpenSSL does not use NEW
//if (s.startsWith("-----BEGIN NEW CERTIFICATE REQUEST-----")) {
private void doPrintCertReq(InputStream in, PrintStream out)
throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
! StringBuffer sb = new StringBuffer();
boolean started = false;
while (true) {
String s = reader.readLine();
if (s == null) break;
if (!started) {
private void doPrintCertReq(InputStream in, PrintStream out)
throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
! StringBuilder sb = new StringBuilder();
boolean started = false;
while (true) {
String s = reader.readLine();
if (s == null) break;
if (!started) {
out.write(cert.getEncoded()); // binary
}
}
/**
- * Converts a byte to hex digit and writes to the supplied buffer
- */
- private void byte2hex(byte b, StringBuffer buf) {
- char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
- '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- int high = ((b & 0xf0) >> 4);
- int low = (b & 0x0f);
- buf.append(hexChars[high]);
- buf.append(hexChars[low]);
- }
-
- /**
- * Converts a byte array to hex string
- */
- private String toHexString(byte[] block) {
- StringBuffer buf = new StringBuffer();
- int len = block.length;
- for (int i = 0; i < len; i++) {
- byte2hex(block[i], buf);
- if (i < len-1) {
- buf.append(":");
- }
- }
- return buf.toString();
- }
-
- /**
* Recovers (private) key associated with given alias.
*
* @return an array of objects, where the 1st element in the array is the
* recovered private key, and the 2nd element is the password used to
* recover it.
throws Exception
{
byte[] encCertInfo = cert.getEncoded();
MessageDigest md = MessageDigest.getInstance(mdAlg);
byte[] digest = md.digest(encCertInfo);
! return toHexString(digest);
}
/**
* Prints warning about missing integrity check.
*/
throws Exception
{
byte[] encCertInfo = cert.getEncoded();
MessageDigest md = MessageDigest.getInstance(mdAlg);
byte[] digest = md.digest(encCertInfo);
! return Hex.encoder(":","", "", true).encode(digest);
}
/**
* Prints warning about missing integrity check.
*/
ObjectIdentifier oid = ObjectIdentifier.of(name);
byte[] data = null;
if (value != null) {
data = new byte[value.length() / 2 + 1];
int pos = 0;
for (char c: value.toCharArray()) {
! int hex;
! if (c >= '0' && c <= '9') {
- hex = c - '0' ;
- } else if (c >= 'A' && c <= 'F') {
- hex = c - 'A' + 10;
- } else if (c >= 'a' && c <= 'f') {
- hex = c - 'a' + 10;
- } else {
continue;
}
if (pos % 2 == 0) {
data[pos/2] = (byte)(hex << 4);
} else {
ObjectIdentifier oid = ObjectIdentifier.of(name);
byte[] data = null;
if (value != null) {
data = new byte[value.length() / 2 + 1];
int pos = 0;
+ Hex.Decoder decoder = Hex.decoder();
for (char c: value.toCharArray()) {
! int hex = decoder.fromHex(c);
! if (hex < 0) {
continue;
}
if (pos % 2 == 0) {
data[pos/2] = (byte)(hex << 4);
} else {
< prev index next >