public class HttpEce
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
KEY_LENGTH |
static int |
SHA_256_LENGTH |
static int |
TAG_SIZE |
static int |
TWO_BYTE_MAX |
static java.lang.String |
WEB_PUSH_INFO |
| Constructor and Description |
|---|
HttpEce() |
HttpEce(java.util.Map<java.lang.String,java.security.KeyPair> keys,
java.util.Map<java.lang.String,java.lang.String> labels) |
| Modifier and Type | Method and Description |
|---|---|
protected static byte[] |
buildInfo(java.lang.String type,
byte[] context)
Future versions might require a null-terminated info string?
|
byte[] |
decrypt(byte[] payload,
byte[] salt,
byte[] key,
java.lang.String keyid,
Encoding version)
Decrypt the payload.
|
byte[] |
decryptRecord(byte[] ciphertext,
byte[] key,
byte[] nonce,
Encoding version) |
byte[][] |
deriveKeyAndNonce(byte[] salt,
byte[] key,
java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
Encoding version,
int mode) |
byte[] |
encrypt(byte[] plaintext,
byte[] salt,
byte[] privateKey,
java.lang.String keyid,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
Encoding version)
Encrypt the given plaintext.
|
byte[][] |
extractSecretAndContext(byte[] key,
java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret) |
protected static byte[] |
hkdfExpand(byte[] ikm,
byte[] salt,
byte[] info,
int length)
Convenience method for computing the HMAC Key Derivation Function.
|
byte[][] |
parseHeader(byte[] payload) |
byte[] |
webpushSecret(java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
int mode)
Combine Shared and Authentication Secrets
See https://tools.ietf.org/html/draft-ietf-webpush-encryption-09#section-3.3.
|
public static final int KEY_LENGTH
public static final int SHA_256_LENGTH
public static final int TAG_SIZE
public static final int TWO_BYTE_MAX
public static final java.lang.String WEB_PUSH_INFO
public HttpEce()
public HttpEce(java.util.Map<java.lang.String,java.security.KeyPair> keys,
java.util.Map<java.lang.String,java.lang.String> labels)
public byte[] encrypt(byte[] plaintext,
byte[] salt,
byte[] privateKey,
java.lang.String keyid,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
Encoding version)
throws java.security.GeneralSecurityException
plaintext - Payload to encrypt.salt - A random 16-byte bufferprivateKey - A private key to encrypt this message with (Web Push: the local private key)keyid - An identifier for the local key. Only applies to AESGCM. For AES128GCM, the header contains the keyid.dh - An Elliptic curve Diffie-Hellman public privateKey on the P-256 curve (Web Push: the user's keys.p256dh)authSecret - An authentication secret (Web Push: the user's keys.auth)version - java.security.GeneralSecurityExceptionpublic byte[] decrypt(byte[] payload,
byte[] salt,
byte[] key,
java.lang.String keyid,
Encoding version)
throws java.security.InvalidKeyException,
java.security.NoSuchAlgorithmException,
javax.crypto.IllegalBlockSizeException,
java.security.InvalidAlgorithmParameterException,
javax.crypto.BadPaddingException,
java.security.NoSuchProviderException,
javax.crypto.NoSuchPaddingException
payload - Header and body (ciphertext)salt - May be null when version is AES128GCM; the salt is extracted from the header.version - AES128GCM or AESGCM.java.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionjavax.crypto.IllegalBlockSizeExceptionjava.security.InvalidAlgorithmParameterExceptionjavax.crypto.BadPaddingExceptionjava.security.NoSuchProviderExceptionjavax.crypto.NoSuchPaddingExceptionpublic byte[][] parseHeader(byte[] payload)
public byte[] decryptRecord(byte[] ciphertext,
byte[] key,
byte[] nonce,
Encoding version)
throws javax.crypto.NoSuchPaddingException,
java.security.NoSuchAlgorithmException,
java.security.NoSuchProviderException,
java.security.InvalidAlgorithmParameterException,
java.security.InvalidKeyException,
javax.crypto.BadPaddingException,
javax.crypto.IllegalBlockSizeException
javax.crypto.NoSuchPaddingExceptionjava.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderExceptionjava.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionprotected static byte[] buildInfo(java.lang.String type,
byte[] context)
type - protected static byte[] hkdfExpand(byte[] ikm,
byte[] salt,
byte[] info,
int length)
public byte[][] extractSecretAndContext(byte[] key,
java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret)
throws java.security.InvalidKeyException,
java.security.NoSuchAlgorithmException
java.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionpublic byte[][] deriveKeyAndNonce(byte[] salt,
byte[] key,
java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
Encoding version,
int mode)
throws java.security.NoSuchAlgorithmException,
java.security.InvalidKeyException
java.security.NoSuchAlgorithmExceptionjava.security.InvalidKeyExceptionpublic byte[] webpushSecret(java.lang.String keyId,
org.bouncycastle.jce.interfaces.ECPublicKey dh,
byte[] authSecret,
int mode)
throws java.security.NoSuchAlgorithmException,
java.security.InvalidKeyException
keyId - dh - authSecret - mode - java.security.NoSuchAlgorithmExceptionjava.security.InvalidKeyException