Search in sources :

Example 1 with CeresProvider

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));
}
Also used : CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Signature(java.security.Signature) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Provider(java.security.Provider)

Example 2 with CeresProvider

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());
}
Also used : CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Signature(java.security.Signature) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Provider(java.security.Provider)

Example 3 with CeresProvider

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");
}
Also used : CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Signature(java.security.Signature) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) KeyStore(java.security.KeyStore) CeresProvider(es.gob.jmulticard.jse.provider.ceres.CeresProvider) Provider(java.security.Provider)

Aggregations

CeresProvider (es.gob.jmulticard.jse.provider.ceres.CeresProvider)3 KeyStore (java.security.KeyStore)3 Provider (java.security.Provider)3 Signature (java.security.Signature)3 X509Certificate (java.security.cert.X509Certificate)2 SmartcardIoConnection (es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection)1