An open API service indexing awesome lists of open source software.

https://github.com/core-lib/cryptogram

Structured object sign and verify framework
https://github.com/core-lib/cryptogram

Last synced: about 1 year ago
JSON representation

Structured object sign and verify framework

Awesome Lists containing this project

README

          

# cryptogram [![](https://www.jitpack.io/v/core-lib/cryptogram.svg)](https://www.jitpack.io/#core-lib/cryptogram)

## Installation
```xml


jitpack.io
https://jitpack.io

com.github.core-lib
cryptogram
1.0.0

commons-codec
commons-codec
1.11

```

## Usage
```java
public class Testing {

@Test
public void test() throws Exception {
Codec signCodec = new HexCodec();
Codec keyCodec = new PlainCodec();
StringifyProvider stringifyProvider = new DefaultStringifyProvider();
SignatureProvider signatureProvider = new HMACSHA256SignatureProvider();
VerificationProvider verificationProvider = new HMACSHA256VerificationProvider();

Cryptography cryptography = new Cryptography(
signCodec,
keyCodec,
stringifyProvider,
signatureProvider,
verificationProvider
);

String secretKey = "io.codex.cryptogram";
Map param = new HashMap();
param.put("username", "codex");
param.put("password", "codex");

{
// HmacSHA256("{password=codex&username=codex}", "io.codex.cryptogram")
String signature = cryptography.sign(param, secretKey);
boolean verified = cryptography.verify(param, signature, secretKey);
assert verified : "A serious bug";
}

{
// HmacSHA256("POST /login?{password=codex&username=codex}&timestamp=1539851150142", "io.codex.cryptogram")
long timestamp = 1539851150142L;
String signature = cryptography.sign(param, "POST /login?", "&timestamp=" + timestamp, secretKey);
boolean verified = cryptography.verify(param, "POST /login?", "&timestamp=" + timestamp, signature, secretKey);
assert verified : "A serious bug";
}
}

}
```