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 800dca9 commit b7bb36a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,7 @@ private class CredentialServiceImpl(
)
preview = offerCredentialData.body.credential_preview
claims <- CredentialService.convertAttributesToJsonClaims(preview.body.attributes)
// FIXME convert to pem format String
sdJwtPrivateKey = SDJWTPrivateKey.fromPem(jwtIssuerKeys.privateKey.toString())
sdJwtPrivateKey = SDJWTPrivateKey.fromPem(SDJWT.convertED25519PrivateKeyToPEM(jwtIssuerKeys.privateKey.getEncoded))
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,4 +68,17 @@ object SDJWT {
val result: Boolean = verifier.verify(claims)
result
}
//FIXME
def convertED25519PrivateKeyToPEM(encodedKey: Array[Byte]): 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 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
}
}

0 comments on commit b7bb36a

Please sign in to comment.