Get Private key from .PKCS12 certificate on android device










0















I am new to android need your help on this.



I have requirement where I have installed .pkcs12 certificate on my android device and need to fetch private key from it.



I have android device (5.0) and upon installing .pkcs12 certificate it is listing out in my user certificate tab under user tab in Trusted credentials.



I have tried below code.



private string GetKey()

using (StreamReader reader = new StreamReader(@"/storage/emulated/0/MyCertP.p12"))

var fs = reader.BaseStream;
KeyStore keystore = KeyStore.GetInstance("PKCS12");
keystore.Load(fs, "cli7890".ToCharArray());

var enm = keystore.Aliases();
String keyAlias = "";
while (enm.HasMoreElements)

keyAlias = (String)enm.NextElement();
var _certificate = keystore.GetCertificate(keyAlias);
var _publicKey = _certificate.PublicKey;

var key = keystore.GetKey(keyAlias, "cli7890".ToCharArray());

KeyStore.PrivateKeyEntry keyEnt = (KeyStore.PrivateKeyEntry)keystore.GetEntry(keyAlias, new KeyStore.PasswordProtection("cli7890".ToCharArray()));

return keyEnt.PrivateKey.ToString();






I am getting some key which is like below
RSA Private CRT Key



modulus: c4e30867519fb567dc5298c7afa90abab037d519244a539ef542d33e054175c349e7fc5a5bf7f3437a5710621011ea4ae5cdcf2798246bbabd1211dce489d68d1c6d5c1da3bd6b7a20cd55a0779db0ba3e0ffdcf5110a955c4a3edfc189415706841411d75e209d210d4df4b3902bad5e3ff45cbcb6405736fe136a017ddfc95



public exponent: 10001



private exponent: 2133d83af43ce6aeb92d04aec824cdb665f9446a950023d1eeb2724547459ec26c383f0a4df02689fe9ba81ba17223fcb57c5baee5ad5ead832d04ee276c474e00f5b25849624351fe99e35a7b257ea41a5b030cc08c35c739ac65a8698600301d0490eac38646474cc3b0e8dc0dcc0663448d97cd055cbc8769b8d212384e01 }



So I am not sure if this is the private key and also I need generate X509Certificate2 object and assign PrivateKey property to it.










share|improve this question
























  • The above code I am trying in C#

    – VinodMG
    Nov 15 '18 at 12:19















0















I am new to android need your help on this.



I have requirement where I have installed .pkcs12 certificate on my android device and need to fetch private key from it.



I have android device (5.0) and upon installing .pkcs12 certificate it is listing out in my user certificate tab under user tab in Trusted credentials.



I have tried below code.



private string GetKey()

using (StreamReader reader = new StreamReader(@"/storage/emulated/0/MyCertP.p12"))

var fs = reader.BaseStream;
KeyStore keystore = KeyStore.GetInstance("PKCS12");
keystore.Load(fs, "cli7890".ToCharArray());

var enm = keystore.Aliases();
String keyAlias = "";
while (enm.HasMoreElements)

keyAlias = (String)enm.NextElement();
var _certificate = keystore.GetCertificate(keyAlias);
var _publicKey = _certificate.PublicKey;

var key = keystore.GetKey(keyAlias, "cli7890".ToCharArray());

KeyStore.PrivateKeyEntry keyEnt = (KeyStore.PrivateKeyEntry)keystore.GetEntry(keyAlias, new KeyStore.PasswordProtection("cli7890".ToCharArray()));

return keyEnt.PrivateKey.ToString();






I am getting some key which is like below
RSA Private CRT Key



modulus: c4e30867519fb567dc5298c7afa90abab037d519244a539ef542d33e054175c349e7fc5a5bf7f3437a5710621011ea4ae5cdcf2798246bbabd1211dce489d68d1c6d5c1da3bd6b7a20cd55a0779db0ba3e0ffdcf5110a955c4a3edfc189415706841411d75e209d210d4df4b3902bad5e3ff45cbcb6405736fe136a017ddfc95



public exponent: 10001



private exponent: 2133d83af43ce6aeb92d04aec824cdb665f9446a950023d1eeb2724547459ec26c383f0a4df02689fe9ba81ba17223fcb57c5baee5ad5ead832d04ee276c474e00f5b25849624351fe99e35a7b257ea41a5b030cc08c35c739ac65a8698600301d0490eac38646474cc3b0e8dc0dcc0663448d97cd055cbc8769b8d212384e01 }



So I am not sure if this is the private key and also I need generate X509Certificate2 object and assign PrivateKey property to it.










share|improve this question
























  • The above code I am trying in C#

    – VinodMG
    Nov 15 '18 at 12:19













0












0








0








I am new to android need your help on this.



I have requirement where I have installed .pkcs12 certificate on my android device and need to fetch private key from it.



I have android device (5.0) and upon installing .pkcs12 certificate it is listing out in my user certificate tab under user tab in Trusted credentials.



I have tried below code.



private string GetKey()

using (StreamReader reader = new StreamReader(@"/storage/emulated/0/MyCertP.p12"))

var fs = reader.BaseStream;
KeyStore keystore = KeyStore.GetInstance("PKCS12");
keystore.Load(fs, "cli7890".ToCharArray());

var enm = keystore.Aliases();
String keyAlias = "";
while (enm.HasMoreElements)

keyAlias = (String)enm.NextElement();
var _certificate = keystore.GetCertificate(keyAlias);
var _publicKey = _certificate.PublicKey;

var key = keystore.GetKey(keyAlias, "cli7890".ToCharArray());

KeyStore.PrivateKeyEntry keyEnt = (KeyStore.PrivateKeyEntry)keystore.GetEntry(keyAlias, new KeyStore.PasswordProtection("cli7890".ToCharArray()));

return keyEnt.PrivateKey.ToString();






I am getting some key which is like below
RSA Private CRT Key



modulus: c4e30867519fb567dc5298c7afa90abab037d519244a539ef542d33e054175c349e7fc5a5bf7f3437a5710621011ea4ae5cdcf2798246bbabd1211dce489d68d1c6d5c1da3bd6b7a20cd55a0779db0ba3e0ffdcf5110a955c4a3edfc189415706841411d75e209d210d4df4b3902bad5e3ff45cbcb6405736fe136a017ddfc95



public exponent: 10001



private exponent: 2133d83af43ce6aeb92d04aec824cdb665f9446a950023d1eeb2724547459ec26c383f0a4df02689fe9ba81ba17223fcb57c5baee5ad5ead832d04ee276c474e00f5b25849624351fe99e35a7b257ea41a5b030cc08c35c739ac65a8698600301d0490eac38646474cc3b0e8dc0dcc0663448d97cd055cbc8769b8d212384e01 }



So I am not sure if this is the private key and also I need generate X509Certificate2 object and assign PrivateKey property to it.










share|improve this question
















I am new to android need your help on this.



I have requirement where I have installed .pkcs12 certificate on my android device and need to fetch private key from it.



I have android device (5.0) and upon installing .pkcs12 certificate it is listing out in my user certificate tab under user tab in Trusted credentials.



I have tried below code.



private string GetKey()

using (StreamReader reader = new StreamReader(@"/storage/emulated/0/MyCertP.p12"))

var fs = reader.BaseStream;
KeyStore keystore = KeyStore.GetInstance("PKCS12");
keystore.Load(fs, "cli7890".ToCharArray());

var enm = keystore.Aliases();
String keyAlias = "";
while (enm.HasMoreElements)

keyAlias = (String)enm.NextElement();
var _certificate = keystore.GetCertificate(keyAlias);
var _publicKey = _certificate.PublicKey;

var key = keystore.GetKey(keyAlias, "cli7890".ToCharArray());

KeyStore.PrivateKeyEntry keyEnt = (KeyStore.PrivateKeyEntry)keystore.GetEntry(keyAlias, new KeyStore.PasswordProtection("cli7890".ToCharArray()));

return keyEnt.PrivateKey.ToString();






I am getting some key which is like below
RSA Private CRT Key



modulus: c4e30867519fb567dc5298c7afa90abab037d519244a539ef542d33e054175c349e7fc5a5bf7f3437a5710621011ea4ae5cdcf2798246bbabd1211dce489d68d1c6d5c1da3bd6b7a20cd55a0779db0ba3e0ffdcf5110a955c4a3edfc189415706841411d75e209d210d4df4b3902bad5e3ff45cbcb6405736fe136a017ddfc95



public exponent: 10001



private exponent: 2133d83af43ce6aeb92d04aec824cdb665f9446a950023d1eeb2724547459ec26c383f0a4df02689fe9ba81ba17223fcb57c5baee5ad5ead832d04ee276c474e00f5b25849624351fe99e35a7b257ea41a5b030cc08c35c739ac65a8698600301d0490eac38646474cc3b0e8dc0dcc0663448d97cd055cbc8769b8d212384e01 }



So I am not sure if this is the private key and also I need generate X509Certificate2 object and assign PrivateKey property to it.







android xamarin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:19









Sagar Zala

2,41651438




2,41651438










asked Nov 15 '18 at 12:13









VinodMGVinodMG

344




344












  • The above code I am trying in C#

    – VinodMG
    Nov 15 '18 at 12:19

















  • The above code I am trying in C#

    – VinodMG
    Nov 15 '18 at 12:19
















The above code I am trying in C#

– VinodMG
Nov 15 '18 at 12:19





The above code I am trying in C#

– VinodMG
Nov 15 '18 at 12:19












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319269%2fget-private-key-from-pkcs12-certificate-on-android-device%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319269%2fget-private-key-from-pkcs12-certificate-on-android-device%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3