net.named_data.jndn.security.identity
public class FilePrivateKeyStorage extends PrivateKeyStorage
Constructor and Description |
---|
FilePrivateKeyStorage()
Create a new FilePrivateKeyStorage to connect to the default directory in
System.getProperty("user.home").
|
FilePrivateKeyStorage(String keyStoreDirectoryPath)
Create a new FilePrivateKeyStorage to connect to the given directory.
|
Modifier and Type | Method and Description |
---|---|
Blob |
decrypt(Name keyName,
ByteBuffer data,
boolean isSymmetric)
Decrypt data.
|
void |
deleteKey(Name keyName)
Delete a key by name; checks all KeyClass types
|
void |
deleteKeyPair(Name keyName)
Delete a pair of asymmetric keys.
|
boolean |
doesKeyExist(Name keyName,
KeyClass keyClass)
Check if a particular key exists.
|
Blob |
encrypt(Name keyName,
ByteBuffer data,
boolean isSymmetric)
Encrypt data.
|
void |
generateKey(Name keyName,
KeyParams params)
Generate a symmetric key.
|
void |
generateKeyPair(Name keyName,
KeyParams params)
Generate a pair of asymmetric keys.
|
static String |
getDefaultDirecoryPath(File filesRoot)
Get the default directory path for private keys based on the files root.
|
static String |
getDefaultDirecoryPath(String filesRoot)
Get the default directory path for private keys based on the files root.
|
PublicKey |
getPublicKey(Name keyName)
Get the public key
|
Blob |
sign(ByteBuffer data,
Name keyName,
DigestAlgorithm digestAlgorithm)
Fetch the private key for keyName and sign the data, returning a signature
Blob.
|
decrypt, encrypt, sign
public FilePrivateKeyStorage()
public FilePrivateKeyStorage(String keyStoreDirectoryPath)
keyStoreDirectoryPath
- The full path of the directory holding the
private key data. This creates the directory if it doesn't exist.
For example, you can get the default directory path from an Android files
directory with getDefaultDirecoryPath(context.getFilesDir())public static String getDefaultDirecoryPath(File filesRoot)
filesRoot
- The root file directory. An Android app can use
context.getFilesDir()public static String getDefaultDirecoryPath(String filesRoot)
filesRoot
- The root file directory.public final void generateKeyPair(Name keyName, KeyParams params) throws SecurityException
generateKeyPair
in class PrivateKeyStorage
keyName
- The name of the key pair.params
- The parameters of the key.SecurityException
public void deleteKeyPair(Name keyName) throws SecurityException
deleteKeyPair
in class PrivateKeyStorage
keyName
- The name of the key pair.SecurityException
public final PublicKey getPublicKey(Name keyName) throws SecurityException
getPublicKey
in class PrivateKeyStorage
keyName
- The name of public key.SecurityException
public final Blob sign(ByteBuffer data, Name keyName, DigestAlgorithm digestAlgorithm) throws SecurityException
sign
in class PrivateKeyStorage
data
- Pointer the input byte buffer to sign.keyName
- The name of the signing key.digestAlgorithm
- the digest algorithm.SecurityException
public final Blob decrypt(Name keyName, ByteBuffer data, boolean isSymmetric) throws SecurityException
decrypt
in class PrivateKeyStorage
keyName
- The name of the decrypting key.data
- The byte buffer to be decrypted, from its position to its
limit.isSymmetric
- If true symmetric encryption is used, otherwise
asymmetric encryption is used.SecurityException
public final Blob encrypt(Name keyName, ByteBuffer data, boolean isSymmetric) throws SecurityException
encrypt
in class PrivateKeyStorage
keyName
- The name of the encrypting key.data
- The byte buffer to be encrypted, from its position to its
limit.isSymmetric
- If true symmetric encryption is used, otherwise
asymmetric encryption is used.SecurityException
public final void generateKey(Name keyName, KeyParams params) throws SecurityException
generateKey
in class PrivateKeyStorage
keyName
- The name of the key.params
- The parameters of the key.SecurityException
public final void deleteKey(Name keyName) throws SecurityException
keyName
- SecurityException
public final boolean doesKeyExist(Name keyName, KeyClass keyClass) throws SecurityException
doesKeyExist
in class PrivateKeyStorage
keyName
- The name of the key.keyClass
- The class of the key, e.g. KeyClass.PUBLIC,
KeyClass.PRIVATE, or KeyClass.SYMMETRIC.SecurityException
Copyright © 2016. All rights reserved.