ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

RSA CIFRADO


Enviado por   •  4 de Marzo de 2018  •  Apuntes  •  377 Palabras (2 Páginas)  •  97 Visitas

Página 1 de 2

RSA/DSA using Java Cryptography Extension

Private and public RSA and DSA keys can be generated using Java

Cryptography Extension (JCE). The following code, courtesy of fellow

API user Nathan W, shows how it can be done:

import java.io.*;

import java.security.*;

public class KeyGen {

    public static void main(String[] args) {

        try {

            KeyPairGenerator keyGen =

                 KeyPairGenerator.getInstance("DSA", "SUN");

            SecureRandom random =

                 SecureRandom.getInstance("SHA1PRNG", "SUN");

            keyGen.initialize(1024, random);

            KeyPair pair = keyGen.generateKeyPair();

            PrivateKey priv = pair.getPrivate();

            PublicKey pub = pair.getPublic();

            byte[] encPriv = priv.getEncoded();

            FileOutputStream privfos =

                new FileOutputStream("DSAPrivateKey.key");

            privfos.write(encPriv);

            privfos.close();

            byte[] encPub = pub.getEncoded();

            FileOutputStream pubfos =

                new FileOutputStream("DSAPublicKey.key");

            pubfos.write(encPub);

            pubfos.close();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

To generate RSA keys instead, replace the KeyPairGenerator instance

with

     KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");

To read more about JCE, visit

http://java.sun.com/j2se/1.5.0/docs/guide/security/CryptoSpec.html

Hope that helps,

Amanda

...

Descargar como (para miembros actualizados)  txt (1.5 Kb)   pdf (60.5 Kb)   docx (10.4 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com