Skip to content

Commit

Permalink
convert to ED25519 to pem
Browse files Browse the repository at this point in the history
Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
  • Loading branch information
mineme0110 committed May 9, 2024
1 parent b7bb36a commit f038c05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema
import org.hyperledger.identus.pollux.core.model.secret.CredentialDefinitionSecret
import org.hyperledger.identus.pollux.core.repository.{CredentialRepository, CredentialStatusListRepository}
import org.hyperledger.identus.pollux.vc.jwt.{ES256KSigner, Issuer as JwtIssuer, *}
import org.hyperledger.identus.shared.crypto.Ed25519KeyPair
import org.hyperledger.identus.shared.http.{DataUrlResolver, GenericUriResolver}
import org.hyperledger.identus.shared.models.WalletAccessContext
import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect
import zio.*
import zio.prelude.ZValidation

import org.hyperledger.identus.castor.core.model.did.EllipticCurve
import java.net.URI
import java.rmi.UnexpectedException
import java.time.{Instant, ZoneId}
Expand Down Expand Up @@ -1298,7 +1299,7 @@ private class CredentialServiceImpl(
)
preview = offerCredentialData.body.credential_preview
claims <- CredentialService.convertAttributesToJsonClaims(preview.body.attributes)
sdJwtPrivateKey = SDJWTPrivateKey.fromPem(SDJWT.convertED25519PrivateKeyToPEM(jwtIssuerKeys.privateKey.getEncoded))
sdJwtPrivateKey = SDJWTPrivateKey.fromPem(SDJWT.convertPrivateKeyToPEM(jwtIssuerKeys.privateKey.getEncoded, EllipticCurve.ED25519.name))
credential = SDJWT.issueCredential(sdJwtPrivateKey, claims.asJson.noSpaces)

issueCredential = IssueCredential.build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ object SDJWT {
val result: Boolean = verifier.verify(claims)
result
}

//FIXME
def convertED25519PrivateKeyToPEM(encodedKey: Array[Byte]): String = {
def convertPrivateKeyToPEM(encodedKey: Array[Byte], algorithm: String): String = {
import java.util.Base64
import java.security.KeyFactory
import java.security.spec.PKCS8EncodedKeySpec
import java.security.PrivateKey

val keySpec = new PKCS8EncodedKeySpec(encodedKey)
val keyFactory = KeyFactory.getInstance("Ed25519")
val keyFactory = KeyFactory.getInstance(algorithm) // Use the passed algorithm
val privateKey: PrivateKey = keyFactory.generatePrivate(keySpec)

val encoded = Base64.getMimeEncoder.encodeToString(privateKey.getEncoded)
val pemKey = s"-----BEGIN PRIVATE KEY-----\n${encoded.grouped(64).mkString("\n")}\n-----END PRIVATE KEY-----"
pemKey
Expand Down

0 comments on commit f038c05

Please sign in to comment.