Giter VIP home page Giter VIP logo

jcrypto's Introduction

jCrypto (Work in progress)

jCrypto provides a more readable Java API in Builder-pattern to create/validate/update PKI and Symmetric keys and KeyStores. jCrypto aims to provide the keytool/openssl's command line options to be provided in a programatic way. It doesn't rely on the com.sun.* classes that are JVM specific and limited visibility, instead it relys on BouncyCastle PKIX utilities to generate X509 certtificates.

Example:

Create Key Pair:

KeyPair keyPair = new KeyPairCreator.Builder()
  .withKeySize(2048)
  .withAlgorithm("RSA")
  ._withProvider("SUN")
  ._withSecureRandom(SecureRandom.getInstance("SHA1PRNG"))
  .build().create();

where some of the builder methods prefixed with _ to indicate optional attributes.

Create self-signed X509 Certificate:

Map<CertAttr, String> subjectAndIssuer = ImmutableMap.of(CertAttr.CN, "skothuri.home.com", CertAttr.C, "IN", CertAttr.O, "Home");

X509Certificate x509Certificate = new X509CertificateCreator.Builder()
  .withPrivateKey(keyPair.getPrivate())
  .withSigningAlgorithm("SHA256withRSA")
  .withValidityStart(startDate)
  .withValidityEnd(JCryptoUtil.daysFrom(startDate, 365))
  .withIssuer(subjectAndIssuer)
  .withSubject(subjectAndIssuer).build().create(keyPair.getPublic());

Signing InoutStream

String testData = "0123456789";

KeyPair keyPair = new KeyPairCreator.Builder().withKeySize(2048).withAlgorithm("RSA").build().create();
byte[] md5withRSAS = new Signer().algorithm("MD5withRSA").privateKey(keyPair.getPrivate())
			.sign(new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8)));

Verifying the Signature

assertTrue(new Verifier().algorithm("MD5withRSA").publicKey(keyPair.getPublic())
			.verify(new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8)), md5withRSAS));

jcrypto's People

Contributors

srinivas-kothuri-now avatar srinivaskothuri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.