Get RSA Public or Private Key from KeyPair Generation Flutter The Next CEO of Stack OverflowPublic & Private Keys in .NET besides RSAUse RSA private key to generate public key?How can I get the private key from an RSA public key?Can we have multiple public keys with a single private key for RSA?RSA Public Key formatJava - Public-private key encryption - how to calculate private key in RSAprivate/public key ssh-keygen -t rsaComputing private key of a user from his RSA public keyGenerate RSA Public Key from Modulus and ExponentFlutter - How can I generate a private/public key pair to encrypt messages
In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?
(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?
Airplane gently rocking its wings during whole flight
What happened in Rome, when the western empire "fell"?
Is dried pee considered dirt?
The Ultimate Number Sequence Puzzle
Calculate the Mean mean of two numbers
Which Pokemon have a special animation when running with them out of their pokeball?
Is it OK to decorate a log book cover?
Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Is it professional to write unrelated content in an almost-empty email?
IC has pull-down resistors on SMBus lines?
Strange use of "whether ... than ..." in official text
What CSS properties can the br tag have?
Physiological effects of huge anime eyes
What steps are necessary to read a Modern SSD in Medieval Europe?
How do I fit a non linear curve?
Cannot shrink btrfs filesystem although there is still data and metadata space left : ERROR: unable to resize '/home': No space left on device
Is it correct to say moon starry nights?
Asymptote: 3d graph over a disc
What are the unusually-enlarged wing sections on this P-38 Lightning?
Inductor and Capacitor in Parallel
Players Circumventing the limitations of Wish
Get RSA Public or Private Key from KeyPair Generation Flutter
The Next CEO of Stack OverflowPublic & Private Keys in .NET besides RSAUse RSA private key to generate public key?How can I get the private key from an RSA public key?Can we have multiple public keys with a single private key for RSA?RSA Public Key formatJava - Public-private key encryption - how to calculate private key in RSAprivate/public key ssh-keygen -t rsaComputing private key of a user from his RSA public keyGenerate RSA Public Key from Modulus and ExponentFlutter - How can I generate a private/public key pair to encrypt messages
I have added pointycastle and generated a keypair, encrypting the trial "Hello World" string. From this, I want to get the values of the Private and Public Key. Is there anywhere they are stored, because whenever I try to print the values of keyPair.privateKey
, it returns Instance of 'RSAPrivateKey
.
Here is the code I used
var keyParams = new RSAKeyGeneratorParameters(new BigInt.from(65537), 2048, 5);
var secureRandom = new FortunaRandom();
var random = new Random.secure();
List<int> seeds = [];
for (int i = 0; i < 32; i++)
seeds.add(random.nextInt(255));
secureRandom.seed(new KeyParameter(new Uint8List.fromList(seeds)));
var rngParams = new ParametersWithRandom(keyParams, secureRandom);
var k = new RSAKeyGenerator();
k.init(rngParams);
var keyPair = k.generateKeyPair();
var cipher = new RSAEngine()..init( true, new PublicKeyParameter<RSAPublicKey>(keyPair.publicKey));
print("pubkey: $keyPair.publicKey.toString()");
var cipherText = cipher.process(new Uint8List.fromList("Hello World".codeUnits));
print("Encrypted: $new String.fromCharCodes(cipherText)");
cipher.init( false, new PrivateKeyParameter<RSAPrivateKey>(keyPair.privateKey));
//cipher.init( false, new PrivateKeyParameter(keyPair.privateKey) )
var decrypted = cipher.process(cipherText);
print("Decrypted: $new String.fromCharCodes(decrypted)");
dart flutter public-key-encryption pointycastle
add a comment |
I have added pointycastle and generated a keypair, encrypting the trial "Hello World" string. From this, I want to get the values of the Private and Public Key. Is there anywhere they are stored, because whenever I try to print the values of keyPair.privateKey
, it returns Instance of 'RSAPrivateKey
.
Here is the code I used
var keyParams = new RSAKeyGeneratorParameters(new BigInt.from(65537), 2048, 5);
var secureRandom = new FortunaRandom();
var random = new Random.secure();
List<int> seeds = [];
for (int i = 0; i < 32; i++)
seeds.add(random.nextInt(255));
secureRandom.seed(new KeyParameter(new Uint8List.fromList(seeds)));
var rngParams = new ParametersWithRandom(keyParams, secureRandom);
var k = new RSAKeyGenerator();
k.init(rngParams);
var keyPair = k.generateKeyPair();
var cipher = new RSAEngine()..init( true, new PublicKeyParameter<RSAPublicKey>(keyPair.publicKey));
print("pubkey: $keyPair.publicKey.toString()");
var cipherText = cipher.process(new Uint8List.fromList("Hello World".codeUnits));
print("Encrypted: $new String.fromCharCodes(cipherText)");
cipher.init( false, new PrivateKeyParameter<RSAPrivateKey>(keyPair.privateKey));
//cipher.init( false, new PrivateKeyParameter(keyPair.privateKey) )
var decrypted = cipher.process(cipherText);
print("Decrypted: $new String.fromCharCodes(decrypted)");
dart flutter public-key-encryption pointycastle
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
@MazinIbrahim yes, that returns the sameInstance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convertRSAPrivateKey
to a readable form.
– Mazin Ibrahim
Mar 8 at 16:41
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55
add a comment |
I have added pointycastle and generated a keypair, encrypting the trial "Hello World" string. From this, I want to get the values of the Private and Public Key. Is there anywhere they are stored, because whenever I try to print the values of keyPair.privateKey
, it returns Instance of 'RSAPrivateKey
.
Here is the code I used
var keyParams = new RSAKeyGeneratorParameters(new BigInt.from(65537), 2048, 5);
var secureRandom = new FortunaRandom();
var random = new Random.secure();
List<int> seeds = [];
for (int i = 0; i < 32; i++)
seeds.add(random.nextInt(255));
secureRandom.seed(new KeyParameter(new Uint8List.fromList(seeds)));
var rngParams = new ParametersWithRandom(keyParams, secureRandom);
var k = new RSAKeyGenerator();
k.init(rngParams);
var keyPair = k.generateKeyPair();
var cipher = new RSAEngine()..init( true, new PublicKeyParameter<RSAPublicKey>(keyPair.publicKey));
print("pubkey: $keyPair.publicKey.toString()");
var cipherText = cipher.process(new Uint8List.fromList("Hello World".codeUnits));
print("Encrypted: $new String.fromCharCodes(cipherText)");
cipher.init( false, new PrivateKeyParameter<RSAPrivateKey>(keyPair.privateKey));
//cipher.init( false, new PrivateKeyParameter(keyPair.privateKey) )
var decrypted = cipher.process(cipherText);
print("Decrypted: $new String.fromCharCodes(decrypted)");
dart flutter public-key-encryption pointycastle
I have added pointycastle and generated a keypair, encrypting the trial "Hello World" string. From this, I want to get the values of the Private and Public Key. Is there anywhere they are stored, because whenever I try to print the values of keyPair.privateKey
, it returns Instance of 'RSAPrivateKey
.
Here is the code I used
var keyParams = new RSAKeyGeneratorParameters(new BigInt.from(65537), 2048, 5);
var secureRandom = new FortunaRandom();
var random = new Random.secure();
List<int> seeds = [];
for (int i = 0; i < 32; i++)
seeds.add(random.nextInt(255));
secureRandom.seed(new KeyParameter(new Uint8List.fromList(seeds)));
var rngParams = new ParametersWithRandom(keyParams, secureRandom);
var k = new RSAKeyGenerator();
k.init(rngParams);
var keyPair = k.generateKeyPair();
var cipher = new RSAEngine()..init( true, new PublicKeyParameter<RSAPublicKey>(keyPair.publicKey));
print("pubkey: $keyPair.publicKey.toString()");
var cipherText = cipher.process(new Uint8List.fromList("Hello World".codeUnits));
print("Encrypted: $new String.fromCharCodes(cipherText)");
cipher.init( false, new PrivateKeyParameter<RSAPrivateKey>(keyPair.privateKey));
//cipher.init( false, new PrivateKeyParameter(keyPair.privateKey) )
var decrypted = cipher.process(cipherText);
print("Decrypted: $new String.fromCharCodes(decrypted)");
dart flutter public-key-encryption pointycastle
dart flutter public-key-encryption pointycastle
asked Mar 8 at 16:08
Epic Gamer_1Epic Gamer_1
2529
2529
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
@MazinIbrahim yes, that returns the sameInstance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convertRSAPrivateKey
to a readable form.
– Mazin Ibrahim
Mar 8 at 16:41
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55
add a comment |
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
@MazinIbrahim yes, that returns the sameInstance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convertRSAPrivateKey
to a readable form.
– Mazin Ibrahim
Mar 8 at 16:41
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
@MazinIbrahim yes, that returns the same
Instance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
@MazinIbrahim yes, that returns the same
Instance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convert
RSAPrivateKey
to a readable form.– Mazin Ibrahim
Mar 8 at 16:41
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convert
RSAPrivateKey
to a readable form.– Mazin Ibrahim
Mar 8 at 16:41
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55
add a comment |
1 Answer
1
active
oldest
votes
Make sure to import package:pointycastle/asymmetric/api.dart
, then use:
var k = RSAKeyGenerator()..init(rngParams);
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = k.generateKeyPair();
RSAPrivateKey privateKey = keyPair.privateKey;
RSAPublicKey publicKey = keyPair.publicKey;
print(privateKey.d); // prints private exponent
print(publicKey.n); // prints modulus
Recreate from the individual parts:
RSAPrivateKey foo = RSAPrivateKey(
privateKey.n,
privateKey.d,
privateKey.p,
privateKey.q,
);
RSAPublicKey bar = RSAPublicKey(publicKey.n, publicKey.e);
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needsp
andq
. Check the constructors ofRSAPrivateKey
andRSAPublicKey
.
– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includesp
andq
so if you're storing your key using that format you'll have those numbers available.)
– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
|
show 2 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066925%2fget-rsa-public-or-private-key-from-keypair-generation-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Make sure to import package:pointycastle/asymmetric/api.dart
, then use:
var k = RSAKeyGenerator()..init(rngParams);
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = k.generateKeyPair();
RSAPrivateKey privateKey = keyPair.privateKey;
RSAPublicKey publicKey = keyPair.publicKey;
print(privateKey.d); // prints private exponent
print(publicKey.n); // prints modulus
Recreate from the individual parts:
RSAPrivateKey foo = RSAPrivateKey(
privateKey.n,
privateKey.d,
privateKey.p,
privateKey.q,
);
RSAPublicKey bar = RSAPublicKey(publicKey.n, publicKey.e);
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needsp
andq
. Check the constructors ofRSAPrivateKey
andRSAPublicKey
.
– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includesp
andq
so if you're storing your key using that format you'll have those numbers available.)
– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
|
show 2 more comments
Make sure to import package:pointycastle/asymmetric/api.dart
, then use:
var k = RSAKeyGenerator()..init(rngParams);
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = k.generateKeyPair();
RSAPrivateKey privateKey = keyPair.privateKey;
RSAPublicKey publicKey = keyPair.publicKey;
print(privateKey.d); // prints private exponent
print(publicKey.n); // prints modulus
Recreate from the individual parts:
RSAPrivateKey foo = RSAPrivateKey(
privateKey.n,
privateKey.d,
privateKey.p,
privateKey.q,
);
RSAPublicKey bar = RSAPublicKey(publicKey.n, publicKey.e);
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needsp
andq
. Check the constructors ofRSAPrivateKey
andRSAPublicKey
.
– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includesp
andq
so if you're storing your key using that format you'll have those numbers available.)
– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
|
show 2 more comments
Make sure to import package:pointycastle/asymmetric/api.dart
, then use:
var k = RSAKeyGenerator()..init(rngParams);
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = k.generateKeyPair();
RSAPrivateKey privateKey = keyPair.privateKey;
RSAPublicKey publicKey = keyPair.publicKey;
print(privateKey.d); // prints private exponent
print(publicKey.n); // prints modulus
Recreate from the individual parts:
RSAPrivateKey foo = RSAPrivateKey(
privateKey.n,
privateKey.d,
privateKey.p,
privateKey.q,
);
RSAPublicKey bar = RSAPublicKey(publicKey.n, publicKey.e);
Make sure to import package:pointycastle/asymmetric/api.dart
, then use:
var k = RSAKeyGenerator()..init(rngParams);
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = k.generateKeyPair();
RSAPrivateKey privateKey = keyPair.privateKey;
RSAPublicKey publicKey = keyPair.publicKey;
print(privateKey.d); // prints private exponent
print(publicKey.n); // prints modulus
Recreate from the individual parts:
RSAPrivateKey foo = RSAPrivateKey(
privateKey.n,
privateKey.d,
privateKey.p,
privateKey.q,
);
RSAPublicKey bar = RSAPublicKey(publicKey.n, publicKey.e);
edited Mar 19 at 17:35
answered Mar 8 at 17:31
Richard HeapRichard Heap
7,72121019
7,72121019
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needsp
andq
. Check the constructors ofRSAPrivateKey
andRSAPublicKey
.
– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includesp
andq
so if you're storing your key using that format you'll have those numbers available.)
– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
|
show 2 more comments
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needsp
andq
. Check the constructors ofRSAPrivateKey
andRSAPublicKey
.
– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includesp
andq
so if you're storing your key using that format you'll have those numbers available.)
– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
From this, can i recreate a key from just the modulus of public key and exponent of private key?
– Epic Gamer_1
Mar 19 at 16:38
Both need the modulus and exponent. The private key also needs
p
and q
. Check the constructors of RSAPrivateKey
and RSAPublicKey
.– Richard Heap
Mar 19 at 16:59
Both need the modulus and exponent. The private key also needs
p
and q
. Check the constructors of RSAPrivateKey
and RSAPublicKey
.– Richard Heap
Mar 19 at 16:59
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
I know you can do that, but from the value of the key, can you make it? (From a single key value?)
– Epic Gamer_1
Mar 19 at 19:27
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includes
p
and q
so if you're storing your key using that format you'll have those numbers available.)– Richard Heap
Mar 19 at 21:31
It doesn't look like it, but try it by supplying dummy values instead. (Incidentally, PKCS#1 format includes
p
and q
so if you're storing your key using that format you'll have those numbers available.)– Richard Heap
Mar 19 at 21:31
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
also, can I generate a .pem file for this?
– Epic Gamer_1
Mar 20 at 11:12
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066925%2fget-rsa-public-or-private-key-from-keypair-generation-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Did you try keyPair.privateKey.toString() ?
– Mazin Ibrahim
Mar 8 at 16:17
@MazinIbrahim yes, that returns the same
Instance of RSAPrivateKey
– Epic Gamer_1
Mar 8 at 16:33
This package is poorly documented.I suggest you take a look inside their github code to figure out how to convert
RSAPrivateKey
to a readable form.– Mazin Ibrahim
Mar 8 at 16:41
@MazinIbrahim I have tried, but I can't see anything converting it into a readable form. I've tried looking in their Object, as well its generation function, but in there it still shows the same instance output
– Epic Gamer_1
Mar 8 at 16:55