# Secp256Identity question

**URL:** <https://forum.dfinity.org/t/secp256identity-question/19511>\
**Category:** Developers\
**Created:** [April 19, 2023, 12:57pm UTC](https://forum.dfinity.org/t/secp256identity-question/19511 "2023-04-19T12:57:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymqqqq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cymqqqq/32/14515_2.png) [@cymqqqq](https://forum.dfinity.org/u/cymqqqq)\
**Post date:** [April 19, 2023, 12:57pm UTC](https://forum.dfinity.org/t/secp256identity-question/19511/1 "2023-04-19T12:57:17Z")

</div>

Hi Difinity Team && Community Developers, I meet some questions when I try to use the principal id to generate secp256identity, the code as the follows:  
I use the principal id as the input, then I can get an account id array, denoted as secret.  
Then I use Secp256Identity.fromSecretKey() to generate identity, it works, but there is a problem:  
When I use the new identity to call getPrincipal(), the result is different from the input principal id, I don’t know why  
export const fromHexString = (hexString: string) =\> {  
return Uint8Array.from(Buffer.from(hexString, ‘base64’));  
}  
export const getAidArrByPid = (pid: Principal) =\> {  
let aid = getAccountId(pid, SUB\_ACCOUNT\_ZERO);  
let aidArr = Uint8Array.from(fromHexString(aid));  
return aidArr;  
}  
let identity1 = Secp256k1KeyIdentity.fromSecretKey(aidArr);

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [April 19, 2023, 1:05pm UTC](https://forum.dfinity.org/t/secp256identity-question/19511/2 "2023-04-19T13:05:08Z")

</div>

A principal is basically an encoded public key. If I understand correctly what you’re trying to do, then you’re trying to generate the private key from a principal. This is not possible. If it were, public key cryptography as we know it would break.

You have to start with a private key, which you can then load into a Secp256k1 identity, which can then display its public key in the form of its principal. From that you can then derive the account id.

---

<div class="post-metadata">

**Author:** ![cymqqqq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cymqqqq/32/14515_2.png) [@cymqqqq](https://forum.dfinity.org/u/cymqqqq)\
**Post date:** [April 19, 2023, 1:09pm UTC](https://forum.dfinity.org/t/secp256identity-question/19511/3 "2023-04-19T13:09:45Z")

</div>

Thx, you’re right, I’m trying to generate the private key from a principal.  
So, it only can generate a secp256identity from a secret key.  
And thank you again
