Decoding keyringPair's encoded field for private key extraction

I’m working with the polkadot.js library and need to extract the private key from a KeyringPair object. Using pair.toJson(password), I obtain an object with an encoded field in base64. After decoding this to hex, I’m unable to use it directly as a private key - attempts to reimport it don’t yield the correct ss58 address.

My process:

  1. pair.toJson(password) to get the encoded field
  2. Base64 decode to hex
  3. Attempt to use the hex as a private key

The resulting key doesn’t correspond to the original address. I’m seeking clarification on the structure of this encoded field and the correct method to extract the actual private key in hex format.

Any insights into the format of the encoded field or the proper decoding process would be greatly appreciated.