giga Well-Known Member Licensed User Longtime User Nov 28, 2012 #1 Does anyone have an example of how to use the encryption library with the KeyPairGenerator function. I have found examples in VB but struggling to write it in B4A. Thanks to ALL for the help.
Does anyone have an example of how to use the encryption library with the KeyPairGenerator function. I have found examples in VB but struggling to write it in B4A. Thanks to ALL for the help.
Erel B4X founder Staff member Licensed User Longtime User Nov 28, 2012 #2 What are you trying to achieve? Upvote 0
giga Well-Known Member Licensed User Longtime User Nov 29, 2012 #3 Erel said: What are you trying to achieve? Click to expand... I am trying to generate public & private keys for a connection to a server from the app I am working on. Thanks Upvote 0
Erel said: What are you trying to achieve? Click to expand... I am trying to generate public & private keys for a connection to a server from the app I am working on. Thanks
Erel B4X founder Staff member Licensed User Longtime User Dec 2, 2012 #4 You can generate the keys with this code: Code: Copy Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey See the documentation: Basic4android - Encryption Upvote 0
You can generate the keys with this code: Code: Copy Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey See the documentation: Basic4android - Encryption
giga Well-Known Member Licensed User Longtime User Dec 2, 2012 #5 Erel said: You can generate the keys with this code: Code: Copy Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey See the documentation: Basic4android - Encryption Click to expand... Thanks Erel, I was taking the more difficult approach to the KeyPairGenerator. I should have tried the simpler way. THANKS Erel!!:sign0162: Upvote 0
Erel said: You can generate the keys with this code: Code: Copy Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey See the documentation: Basic4android - Encryption Click to expand... Thanks Erel, I was taking the more difficult approach to the KeyPairGenerator. I should have tried the simpler way. THANKS Erel!!:sign0162:
giga Well-Known Member Licensed User Longtime User Dec 3, 2012 #6 Well I made some headway, But cannot get the keys to write to a file(s). Code: Copy Dim MyKey() As String Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey(MyKey) Write.Initialize(File.OpenOutput(DirName, FileName3, False)) File.WriteString(DirName, FileName3, MyKey) Write.Close I have the Filename specified in Sub Process_global but when compiling I get this error: Object reference not set to an instance of an object. (MyKey) Thanks for any advice or help on this. Upvote 0
Well I made some headway, But cannot get the keys to write to a file(s). Code: Copy Dim MyKey() As String Dim kpg As KeyPairGenerator kpg.Initialize("RSA", 128) kpg.GenerateKey(MyKey) Write.Initialize(File.OpenOutput(DirName, FileName3, False)) File.WriteString(DirName, FileName3, MyKey) Write.Close I have the Filename specified in Sub Process_global but when compiling I get this error: Object reference not set to an instance of an object. (MyKey) Thanks for any advice or help on this.
Erel B4X founder Staff member Licensed User Longtime User Dec 4, 2012 #7 GenerateKey doesn't expect any parameter. You should use kpg.PrivateKeyToBytes to get an array of bytes with the key. You can then save it to a file with OutputStream. Upvote 0
GenerateKey doesn't expect any parameter. You should use kpg.PrivateKeyToBytes to get an array of bytes with the key. You can then save it to a file with OutputStream.
giga Well-Known Member Licensed User Longtime User Dec 4, 2012 #8 Erel said: GenerateKey doesn't expect any parameter. You should use kpg.PrivateKeyToBytes to get an array of bytes with the key. You can then save it to a file with OutputStream. Click to expand... Thanks Erel, I set the PrivateKeyToBytes and it is working to produce the key however they are ALL numbers and dashes. (i.e 48-127-5721048-127-876742-) Is there a parameter for letters and numbers? :sign0104: Upvote 0
Erel said: GenerateKey doesn't expect any parameter. You should use kpg.PrivateKeyToBytes to get an array of bytes with the key. You can then save it to a file with OutputStream. Click to expand... Thanks Erel, I set the PrivateKeyToBytes and it is working to produce the key however they are ALL numbers and dashes. (i.e 48-127-5721048-127-876742-) Is there a parameter for letters and numbers? :sign0104:
giga Well-Known Member Licensed User Longtime User Dec 11, 2012 #10 I am taking a shot in the dark with this code. working on generating keypairs Private/Public. With Erels help I was able to get the Key in numeric with dashes but not letters. Therefore not able to get the keys in a true PKCS#8 format. The server I am connecting to will not accept the key in its current state with dashes. With the code below I keep getting and error "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" No matter what number I put in. I could not find any further examples of the code. Code: Copy Dim Formats(1,0) As String Dim kpg As KeyPairGenerator Dim MyKeyB(0) As Byte Dim MyKeyC(0) As List Dim MyKeyD(1) As Byte Dim MyKeyE(1) As List kpg.Initialize("RSA",128) kpg.GenerateKey MyKeyB = kpg.PrivateKeyToBytes kpg.PrivateKeyFromBytes(MyKeyB) MyKeyC(0) = kpg.PrivateKey MyKeyD = kpg.PublicKeyToBytes kpg.PublicKeyFromBytes(MyKeyD) MyKeyE(1) = kpg.PublicKey Is this correct or am I going about this all wrong? Thanks for any Help. Upvote 0
I am taking a shot in the dark with this code. working on generating keypairs Private/Public. With Erels help I was able to get the Key in numeric with dashes but not letters. Therefore not able to get the keys in a true PKCS#8 format. The server I am connecting to will not accept the key in its current state with dashes. With the code below I keep getting and error "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" No matter what number I put in. I could not find any further examples of the code. Code: Copy Dim Formats(1,0) As String Dim kpg As KeyPairGenerator Dim MyKeyB(0) As Byte Dim MyKeyC(0) As List Dim MyKeyD(1) As Byte Dim MyKeyE(1) As List kpg.Initialize("RSA",128) kpg.GenerateKey MyKeyB = kpg.PrivateKeyToBytes kpg.PrivateKeyFromBytes(MyKeyB) MyKeyC(0) = kpg.PrivateKey MyKeyD = kpg.PublicKeyToBytes kpg.PublicKeyFromBytes(MyKeyD) MyKeyE(1) = kpg.PublicKey Is this correct or am I going about this all wrong? Thanks for any Help.
Erel B4X founder Staff member Licensed User Longtime User Dec 12, 2012 #11 There are several mistakes in your code. kpg.PrivateKey doesn't return a byte. Upvote 0
giga Well-Known Member Licensed User Longtime User Dec 12, 2012 #12 Erel said: There are several mistakes in your code. kpg.PrivateKey doesn't return a byte. Click to expand... Back to the drawing board Upvote 0
Erel said: There are several mistakes in your code. kpg.PrivateKey doesn't return a byte. Click to expand... Back to the drawing board