0

I am using Azure key vault for a pet project and I am creating Secp256k1 key pair. Steps to create the key in Azure:

  1. Open your Key Vault resource
  2. Choose Keys from the left side panel.
  3. Click Generate/Import from the top left corner.
  4. Chose Key Type: EC, EC name: P-256K (Secp256k1 basically)
  5. Click Create.

Once I try to access the Public part of the key from my Go-lang app using below code:

func main(){

authorizer, err := kvauth.NewAuthorizerFromEnvironment()
    if err != nil {
        fmt.Printf("unable to create vault authorizer: %v\n", err)
        os.Exit(1)
    }

    basicClient := keyvault.New()
    basicClient.Authorizer = authorizer

    getKey(basicClient, KeyName)

}

func getKey(basicClient keyvault.BaseClient, keyname string) {
    keyResp, err := basicClient.GetKey(context.Background(), "https://"+vaultName+".vault.azure.net", keyname, "")
    if err != nil {
        fmt.Printf("unable to get value for key: %v\n", err)
        os.Exit(1)
    }
    fmt.Println("X = ",*keyResp.Key.X)
    fmt.Println("Y = ",*keyResp.Key.Y)    
}

You can look at the different attributes of the Key listed here at Mircosoft Docs. https://learn.microsoft.com/en-us/rest/api/keyvault/create-key/create-key#request-body

Above code gives me an output as:
X = uAv6rXZedQbihGUQwFkEZl35LeI7OHdhHSOEf3VpXyw
Y = Q8MzSQGOtqT41lsYU-P82o6Fryn8Vnub0l0kdOOdOHI

The given keys are 43 chars in length, while I understand by reading about Secp256k1 that these are 32 chars only. The key size being 43 is giving me an error in the application I intend to use it at.

Am I missing something here or Azure gives some extra characters or something like that? Any help appreciated.

  • 1
    X and Y are Base64url encoded. If you Base64url decode them, they are 32 bytes long each (check this e.g. [here](https://cryptii.com/pipes/base64-to-hex)). – Topaco Oct 27 '21 at 11:46
  • Yes, @Topaco is right Base64url encoded and you can get all the details on this page https://openid.net/specs/draft-jones-json-web-key-03.html section 4.2.1. – kshitij chaurasiya Oct 27 '21 at 11:57

0 Answers0