IC4J API Docs
  • Overview
    • Introduction
  • Quick Start
  • License
  • Reference
    • API Reference
      • Install IC4J Libraries
      • Supported Types
      • ReplicaTransport
      • Identity
      • Principal
      • AgentBuilder
      • ProxyBuilder
      • Using IDLArgs
      • QueryBuilder and UpdateBuilder
      • Using Raw Agent Methods
      • Handle Binary Payloads
      • Object Serializers and Deserializers
        • Pojo Serializer and Deserializer
        • JSON Jackson Serializer and Deserializer
        • JSON Gson Serializer and Deserializer
        • XML DOM Serializer and Deserializer
        • XML JAXB Serializer and Deserializer
        • JDBC Serializer
      • Android Development
Powered by GitBook
On this page
  • AnonymousIdentity
  • BasicIdentity (ED25519)
  • Secp256k1Identity
  1. Reference
  2. API Reference

Identity

PreviousReplicaTransportNextPrincipal

Last updated 2 years ago

IC4J Java Agent currently supports 3 different identity mechanisms. To learn more about the Internet Computer identity mechanisms refer to the Dfinity .

IC4J Agent uses the open source Java cryptography library in its implementation.

If or is being used, define Bouncy Castle as the Java security provider in the code, before an Identity is created.

Security.addProvider(new BouncyCastleProvider());

AnonymousIdentity

AnonymousIdentity is the default mechanism in the IC4J Agent ; this means that if the identity is not specified explicitly , will be assigned implicitly.

To explicitly create the object, the AnonymousIdentity Constructor can be used.

Identity identity = new AnonymousIdentity();

BasicIdentity (ED25519)

The Internet Computer provides support for signatures. The tool can be used to generate the identity PEM file.

dfx identity new alice
cp ~/.config/dfx/identity/xxx/identity.pem alice.pem

Either the Java or Java can be used to read the ED22219 PEM resource to create the object.

Reader sourceReader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream(ED25519_IDENTITY_FILE));
identity = BasicIdentity.fromPEMFile(sourceReader);
Path path = Paths.get(getClass().getClassLoader().getResource(ED25519_IDENTITY_FILE).getPath());
Identity identity = BasicIdentity.fromPEMFile(path);
KeyPair keyPair = KeyPairGenerator.getInstance("Ed25519").generateKeyPair();
Identity identity = BasicIdentity.fromKeyPair(keyPair);

The Java byte[] array can also be used as an input parameter.

byte[] input;
Identity identity = BasicIdentity.fromPEM(input);

Secp256k1Identity

Reader sourceReader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream(ED25519_IDENTITY_FILE));
identity = Secp256k1Identity.fromPEMFile(sourceReader);
Path path = Paths.get(getClass().getClassLoader().getResource(ED25519_IDENTITY_FILE).getPath());
Identity identity = Secp256k1Identity.fromPEMFile(path);
Identity identity = Secp256k1Identity.fromKeyPair(keyPair);

Another option is to use Java as an input parameter.

The Internet Computer also supports signatures commonly used with Bitcoin or Ethereum.

Either Java or Java can be used to read the Secp256k1 PEM resource to create the object.

Another option is to use Java as an input parameter.

To see a fully functional Java sample with all 3 Identity mechanisms refer to this Github .

documentation
Bouncy Castle
BasicIndentity
Secp256k1Identity
AnonymousIdentity
AnonymousIdentity
ED25519
dfx
Reader
Path
BasicIdentity
KeyPair
Secp256k1
Reader
Path
Secp256k1Identity
KeyPair
sample