use of es.gob.jmulticard.jse.provider.ceres.CeresProvider in project jmulticard by ctt-gob-es.
the class TestJseProviderCeres method main.
/**
* Main.
* @param args No se usa.
* @throws Exception En cualquier error.
*/
public static void main(final String[] args) throws Exception {
// TestJseProviderCeres.testProviderWithCustomConnection();
// TestJseProviderCeres.testProviderWithDefaultConnection();
final Provider p = new CeresProvider();
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("CERES");
final char[] pin = new UIPasswordCallback(// $NON-NLS-1$
"PIN de la tarjeta CERES", null, // $NON-NLS-1$
"Introduzca el PIN de la tarjeta CERES", // $NON-NLS-1$
"PIN FNMT-RCM-CERES").getPassword();
ks.load(null, pin);
final Enumeration<String> aliases = ks.aliases();
String alias = null;
// $NON-NLS-1$
System.out.println("Encontrados los siguientes certificados:");
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(AOUtil.getCN((X509Certificate) ks.getCertificate(alias)));
}
System.out.println();
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("Se hara una firma de prueba con '" + AOUtil.getCN((X509Certificate) ks.getCertificate(alias)) + "'");
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign((PrivateKey) ks.getKey(alias, pin));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
final byte[] sign = signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente:");
System.out.println(HexUtils.hexify(sign, true));
}
use of es.gob.jmulticard.jse.provider.ceres.CeresProvider in project jmulticard by ctt-gob-es.
the class TestJseProviderCeres method testProviderWithDefaultConnection.
static void testProviderWithDefaultConnection() throws Exception {
final Provider p = new CeresProvider();
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("CERES");
ks.load(null, PASSWORD);
final Enumeration<String> aliases = ks.aliases();
String alias = null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(alias);
}
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign((PrivateKey) ks.getKey(alias, PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente");
System.out.println(((X509Certificate) ks.getCertificate(alias)).getIssuerX500Principal().toString());
}
use of es.gob.jmulticard.jse.provider.ceres.CeresProvider in project jmulticard by ctt-gob-es.
the class TestJseProviderCeres method testProviderWithCustomConnection.
static void testProviderWithCustomConnection() throws Exception {
final Provider p = new CeresProvider(new SmartcardIoConnection());
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("CERES");
ks.load(null, PASSWORD);
final Enumeration<String> aliases = ks.aliases();
String alias = null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(alias);
}
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign((PrivateKey) ks.getKey(alias, PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente");
}
Aggregations