Skip to content

The Java implementation of a simple, opinionated library for encrypting small packets of data securely. Designed for exchanging tokens among systems written in a variety of programming languages.

timshadel/simple-secrets.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-secrets.java Build Status

The Java implementation of a simple, opinionated library for encrypting small packets of data securely. Designed for exchanging tokens among systems written in a variety of programming languages:

Maven

To include the library in a Maven project, use this definition:

<dependency>
  <groupId>com.timshadel</groupId>
  <artifactId>simple-secrets</artifactId>
  <version>1.0.4</version>
</dependency>

The library is hosted in Sonatype's OSS repository and the Maven Central repository.

Examples

Basic

Send:

import com.timshadel.simplesecrets.Packet;

// Try `head /dev/urandom | shasum -a 256` to make a decent 256-bit key
Packet packet = new Packet("<64-char hex string master key (32 bytes, 256 bits)>");

Map<String, String> message = new HashMap<String, String>();
message.put( "msg", "This is a secret message!" );
String websafe = sender.pack(message);
// => "sJfaVoPxR7OSxiTNOG7_DeOQ7hzCooPdTpaR0c0MJTJZW24ule-g7JJqI5-KXt4GbAIY0jOel8HuZooWhMjW_lElOjvTjJ51T6C6r2lOPCHT5La2hEl-x9Zm9WyeIUw05XRhulDn"

Receive:

import com.timshadel.simplesecrets.Packet;

// Using the same shared key
Packet packet = new Packet("<shared-key-hex>");

// Read data from somewhere (i.e. Request headers, request param, etc.)
String websafe = "sJfaVoPxR7OSxiTNOG7_DeOQ7hzCooPdTpaR0c0MJTJZW24ule-g7JJqI5-KXt4GbAIY0jOel8HuZooWhMjW_lElOjvTjJ51T6C6r2lOPCHT5La2hEl-x9Zm9WyeIUw05XRhulDn";

Map<String, String> message = sender.unpack(websafe, Map<String, String>.class);
message.get("msg")  // => "This is a secret message!"

Can you add ...

This implementation follows the spec for the Node.js version for 100% compatibility.

License

MIT.

About

The Java implementation of a simple, opinionated library for encrypting small packets of data securely. Designed for exchanging tokens among systems written in a variety of programming languages.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages