public class CryptoUtils extends Object
Constructor | Description |
---|---|
CryptoUtils() |
Modifier and Type | Method | Description |
---|---|---|
protected static String |
base64encode(byte[] data) |
|
protected static String |
base64encode(byte[] data,
int len) |
|
static String |
getIssuerHash(X509Certificate cert) |
Return a certificate's issuer hash.
|
static String |
getSubjectHash(X509Certificate cert) |
Return a certificate's subject hash.
|
static String |
getSubjectHash(PKCS10CertificationRequest req) |
Return a certificate signing request's subject hash.
|
static long |
getX509DaysValid(X509Certificate cert) |
Return number of days that certificate is still valid
|
static long |
getX509MillisecondsValid(X509Certificate cert) |
Return number of millseconds that certificate is still valid
|
static long |
getX509NameHash(X500Principal p) |
Return the hash of an X509Name.
|
static long |
getX509NameHash(X509Name p) |
Return the hash of an X509Name.
|
static String |
SignSMIME(String msg,
PrivateKey key,
X509Certificate cert) |
S/MIME sign a string.
|
public static String getSubjectHash(X509Certificate cert) throws NoSuchAlgorithmException, IOException
This is equal to the value computed by openssl x509 -hash -noout -in cert.pem
.
NoSuchAlgorithmException
IOException
public static String getSubjectHash(PKCS10CertificationRequest req) throws NoSuchAlgorithmException, IOException
Same as getSubjectHash(java.security.cert.X509Certificate)
but for a CSR. No openssl equivalent.
public static String getIssuerHash(X509Certificate cert) throws NoSuchAlgorithmException, IOException
This is equal to the value computed by openssl x509 -issuer_hash -noout -in cert.pem
.
NoSuchAlgorithmException
IOException
public static long getX509NameHash(X509Name p) throws NoSuchAlgorithmException, IOException
Same as openssl's X509_NAME_hash()
.
NoSuchAlgorithmException
IOException
public static long getX509NameHash(X500Principal p) throws NoSuchAlgorithmException, IOException
public static long getX509MillisecondsValid(X509Certificate cert)
public static long getX509DaysValid(X509Certificate cert)
public static String SignSMIME(String msg, PrivateKey key, X509Certificate cert) throws GeneralSecurityException, SMIMEException, IOException
The output is a MIME message consisting of two parts. The first is the MIME-encoded string supplied as input, the second is the message signed by the key with certificate embedded.
Example output:
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha256;
boundary="----=_Part_1_190331520.1253198584335"
------=_Part_1_190331520.1253198584335
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is my important piece of text.
------=_Part_1_190331520.1253198584335
Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature
OTAzMDMwMDAwMDBaFw0xMDAzMDMxMDQ5MDFaMFAxEjAQBgNVBAoTCWR1dGNoZ3JpZDEOMAwGA1UE
ChMFdXNlcnMxDzANBgNVBAoTBm5pa2hlZjEZMBcGA1UEAxMQV2lsbGVtIHZhbiBFb.......etc.
yAAAAAAAAA==
------=_Part_1_190331520.1253198584335--
protected static String base64encode(byte[] data)
protected static String base64encode(byte[] data, int len)
Copyright © 2010-2018 Nikhef / Stichting FOM. All Rights Reserved.