Crypt4j

Unix crypt(3) for Java.

License

License

GroupId

GroupId

org.soulwing
ArtifactId

ArtifactId

crypt4j
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Crypt4j
Unix crypt(3) for Java.
Project URL

Project URL

https://github.com/soulwing/crypt4j
Source Code Management

Source Code Management

https://github.com/soulwing/crypt4j

Download crypt4j

How to add to project

<!-- https://jarcasting.com/artifacts/org.soulwing/crypt4j/ -->
<dependency>
    <groupId>org.soulwing</groupId>
    <artifactId>crypt4j</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.soulwing/crypt4j/
implementation 'org.soulwing:crypt4j:1.0.1'
// https://jarcasting.com/artifacts/org.soulwing/crypt4j/
implementation ("org.soulwing:crypt4j:1.0.1")
'org.soulwing:crypt4j:jar:1.0.1'
<dependency org="org.soulwing" name="crypt4j" rev="1.0.1">
  <artifact name="crypt4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.soulwing', module='crypt4j', version='1.0.1')
)
libraryDependencies += "org.soulwing" % "crypt4j" % "1.0.1"
[org.soulwing/crypt4j "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
commons-codec : commons-codec jar 1.10

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

crypt4j

Build Status Maven Central

A Java implementation of the crypt(3) function provided in the GNU C library (glibc). This implementation supports the MD5, SHA-256, and SHA-512 variants. Additionally, it supports legacy DES by way of the Commons Codec library.

Maven Artifacts

To use crypt4j in a Maven project, simply include the following dependency in your POM. Crypt4j is available via [Maven Central] (http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.soulwing%22).

<dependencies>
  ...
  <dependency>
    <groupId>org.soulwing</groupId>
    <artifactId>crypt4j</artifactId>
    <version>1.0.0</version>
  </dependency>
  <!-- optional: needed only if you require DES password encryption -->
  <dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.10</version>
  </dependency>
  ...  
</dependencies>

Usage

The Crypt.crypt static method provides the main entry point. The calling arguments are consistent with the crypt(3) function.

import org.soulwing.crypt4j.Crypt;

... {
  // SHA-512 
  String sha512 = Crypt.crypt("Hello world!".toCharArray(), "$6$saltstring");
  assert sha512.equals("$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1");
  
  // SHA-256
  String sha256 = Crypt.crypt("Hello world!".toCharArray(), "$5$saltstring");
  assert sha256.equals("$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5");
  
  // MD5
  String md5 = Crypt.crypt("Hello world!".toCharArray(), "$1$saltstring");
  assert md5.equals("$1$saltstri$YMyguxXMBpd2TEZ.vS/3q1");
  
  // DES
  // Requires Commons Codec
  // or a NoSuchAlgorithmException will be thrown
  String des = Crypt.crypt("Hello world!".toCharArray(), "saltstring");
  assert des.equals("saszt8mUri4AI");
}

For simple testing you can simply run it as a jar file, passing the password and salt string as quoted command line arguments.

The resulting encrypted password string will be written to standard output.

$ java -jar crypt4j.jar 'topsecret' '$6$tRiCkYsAlT'
$6$tRiCkYsAlT$NqxbcVeBHENLGNhXmZY5EB7RZFuLHuzei..4YthS9/SQmwa81pyZBocelML3OXWhSf4ihk9L4VB0dDIdQALtv0
org.soulwing

soulwing-org

Versions

Version
1.0.1
1.0.0