Identity

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

IC4J Agent uses the open source Java cryptography library Bouncy Castle arrow-up-rightin its implementation.

If BasicIndentityarrow-up-right or Secp256k1Identityarrow-up-right 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 , AnonymousIdentityarrow-up-right will be assigned implicitly.

To explicitly create the AnonymousIdentityarrow-up-right object, the AnonymousIdentity Constructor can be used.

Identity identity = new AnonymousIdentity();

BasicIdentity (ED25519)

The Internet Computer provides support for ED25519arrow-up-right signatures. The dfxarrow-up-right 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 Reader arrow-up-rightor Java Patharrow-up-right can be used to read the ED22219 PEM resource to create the BasicIdentityarrow-up-right 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);

Another option is to use Java KeyPairarrow-up-right as an input parameter.

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

Secp256k1Identity

The Internet Computer also supports Secp256k1arrow-up-right signatures commonly used with Bitcoin or Ethereum.

Either Java Reader arrow-up-rightor Java Patharrow-up-right can be used to read the Secp256k1 PEM resource to create the Secp256k1Identityarrow-up-right object.

Another option is to use Java KeyPairarrow-up-right as an input parameter.

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

Last updated