Author: jaz
Date: Thu Apr 12 09:32:00 2007
New Revision: 528015
URL:
http://svn.apache.org/viewvc?view=rev&rev=528015Log:
updated some methods related to certs
Modified:
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/KeyStoreUtil.java
Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/KeyStoreUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/KeyStoreUtil.java?view=diff&rev=528015&r1=528014&r2=528015==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/KeyStoreUtil.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/KeyStoreUtil.java Thu Apr 12 09:32:00 2007
@@ -46,6 +46,8 @@
import javax.crypto.SecretKey;
import javax.crypto.spec.DHParameterSpec;
+import org.apache.commons.codec.binary.Base64;
+
/**
* KeyStoreUtil - Utilities for getting KeyManagers and TrustManagers
*
@@ -223,7 +225,7 @@
byte[] certBuf = cert.getEncoded();
StringBuffer buf = new StringBuffer();
buf.append("-----BEGIN CERTIFICATE-----\n");
- buf.append(Base64.base64Encode(certBuf));
+ buf.append(new String(Base64.encodeBase64Chunked(certBuf)));
buf.append("\n-----END CERTIFICATE-----\n");
return buf.toString();
}
@@ -262,6 +264,7 @@
// in between the header and footer is the actual certificate
while ((line = reader.readLine()) != null && !line.equals(footer)) {
+ line = line.replaceAll("\\s", "");
ps.print(line);
}
@@ -274,8 +277,13 @@
// decode the buffer to a X509Certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
- byte[] certBytes = Base64.base64Decode(baos.toByteArray());
+ byte[] certBytes = Base64.decodeBase64(baos.toByteArray());
return cf.generateCertificate(new ByteArrayInputStream(certBytes));
+ }
+
+ public static String pemToPkHex(String certString) throws IOException, CertificateException {
+ Certificate cert = pemToCert(certString);
+ return StringUtil.toHexString(cert.getPublicKey().getEncoded());
}
public static SecretKey generateSecretKey(PrivateKey ourKey, PublicKey theirKey) throws Exception {