Sahamati / rahasya

The project aims to simplify the usage of ECC curve (curve25519) with Diffie-Hellman Key exchange. The work is inline with the Account Aggregator Specification.
Apache License 2.0
13 stars 20 forks source link

encoded key spec not recognized: algorithm identifier 1.3.101.110 in key not recognised #36

Open gulfamali opened 1 year ago

gulfamali commented 1 year ago

I'm generating x25519 keypair using crypto.generateKeyPairSync in Node.js. But on providing the generated public key in FI data request (/FI/request) api, AA is responding with Invalid DHPublic Key error message. Also following is the error, AA is encountering at their side:

java.security.spec.InvalidKeySpecException: encoded key spec not recognized: 
algorithm identifier 1.3.101.110 in key not recognised
at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic

KeyMaterial that I'm sending:

KeyMaterial: {
    cryptoAlg: 'ECDH',
    curve: 'Curve25519',
    params: 'params',
    DHPublicKey: {
      expiry: '2023-11-20T15:47:05.451Z',
      Parameters: 'params',
      KeyValue: '-----BEGIN PUBLIC KEY-----MCowBQYDK2VuAyEAaKvrY7xCymrRWADcThoGUGmQUYP6sgfeO9lvBHoRM1Y=-----END PUBLIC KEY-----'
    },
    Nonce: 'Zjc0ZjczMjMtZmE4Zi00MDUzLThkOTQtYmE4Mzc2YzJkY2Ri'
  }

Node.js code that I'm using to generate keypair is given below and also provided in this repo here.

function generateKeyPair(password: string){
    const x25519Keys = crypto.generateKeyPairSync("x25519", { publicKeyEncoding: {
      type: "spki",
      format: "pem"
    },
    privateKeyEncoding: {
      type: "pkcs8",
      format: "pem",
      cipher: "aes-256-cbc",
      passphrase: password
    }
  });
  return x25519Keys;
}

Is there anything I'm missing or doing incorrect here?

@gsasikumar