spongycastle

Retrieve ECC Public Key from Base64 encoded string

浪尽此生 提交于 2019-12-07 17:33:41
问题 I've been trying to create an instance of java.security.PublicKey using a Base64 encoded ECC public key. MainActivity.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { byte[] data = decodePublicKey("AsIAEFjzIcX+Kvhe8AmLoGUc8aYAEAwf5ecREGZ2u4RLxQuav/A="); PublicKey publicKey = loadPublicKey("secp128r1", data); Log.d(TAG, publicKey.toString()); } catch (SQLException | IOException |

Using Spongycastle with Proguard

非 Y 不嫁゛ 提交于 2019-12-06 01:18:16
I've been strugling with proguard to make Spongycastle work. Most of the time, the problem comes when I'm exporting a signed APK, either I've got error, or the app will just crash before starting. So, I've managed to gather informations to get a working proguard configuration : -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontpreverify -verbose -repackageclasses '' -allowaccessmodification -keepattributes *Annotation* -optimizations !code/simplification/arithmetic -libraryjars C:\Program Files\Java\jre7\lib\rt.jar

Retrieve ECC Public Key from Base64 encoded string

Deadly 提交于 2019-12-05 18:21:30
I've been trying to create an instance of java.security.PublicKey using a Base64 encoded ECC public key. MainActivity.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { byte[] data = decodePublicKey("AsIAEFjzIcX+Kvhe8AmLoGUc8aYAEAwf5ecREGZ2u4RLxQuav/A="); PublicKey publicKey = loadPublicKey("secp128r1", data); Log.d(TAG, publicKey.toString()); } catch (SQLException | IOException | GeneralSecurityException e) { Log.e(TAG, e.getMessage(), e); } } private byte[] decodePublicKey(String s) throws

Are there advantages for using SpongyCastle over BouncyCastle, if targeting Android 3.0 and later?

ⅰ亾dé卋堺 提交于 2019-12-05 05:22:45
If I understand the situation correctly, SpongyCastle is a renaming of BouncyCastle and it was created to give people the ability to include a new version of BouncyCastle on Android, since just including the latest BouncyCastle jar would cause conflicts with the old and stripped down version of BouncyCastle that came with Android. However, apparently since version 3.0 (in 2011 - 6 years ago!) the Android BouncyCastle package was renamed to com.android.org.bouncycastle , so that now if you included the regular org.bouncycastle , this would no longer conflict with the pre-packaged stripped down

ECC algorithm key mismatch

纵然是瞬间 提交于 2019-12-03 14:15:41
问题 I am trying to implement ECC algorithm on Android. I am currently using spongy castle to implement it. The key generation cone snippet is as follows : KeyPairGenerator kpg = null; try { kpg = KeyPairGenerator.getInstance("ECIES");// Do i have to do any changes here? } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } ECGenParameterSpec brainpoolP160R1 = new ECGenParameterSpec("brainpoolP160R1"); try { kpg.initialize(brainpoolP160R1); } catch (InvalidAlgorithmParameterException) { }

Android Encrypting String using RSA Public key

房东的猫 提交于 2019-12-03 14:04:54
问题 I am working in a project where I have to encrypt password using RSA public key. I tried many samples and solutions from SO like as follows Android RSA encryption from public string RSA using SpongyCastle But none of the solutions worked in my case unfortunately. I was getting following exceptions repeatedly if i try with any work around Error Log: 04-21 07:50:57.876 18842-18842/com.takeoffandroid.passwordencryption W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter

ECC algorithm key mismatch

橙三吉。 提交于 2019-12-03 04:07:30
I am trying to implement ECC algorithm on Android. I am currently using spongy castle to implement it. The key generation cone snippet is as follows : KeyPairGenerator kpg = null; try { kpg = KeyPairGenerator.getInstance("ECIES");// Do i have to do any changes here? } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } ECGenParameterSpec brainpoolP160R1 = new ECGenParameterSpec("brainpoolP160R1"); try { kpg.initialize(brainpoolP160R1); } catch (InvalidAlgorithmParameterException) { } KeyPair kp = kpg.generateKeyPair(); PublicKey publicKey = kp.getPublic(); PrivateKey privateKey = kp

Export RSA public key to PEM String using java

走远了吗. 提交于 2019-11-30 21:35:06
So I'm using Spongy Castle (Android) to generate a PEM encoded string for an RSA public key that will be uploaded to a server. This is what I'm currently doing: PublicKey publicKey = keyPair.getPublic(); StringWriter writer = new StringWriter(); PemWriter pemWriter = new PemWriter(writer); pemWriter.writeObject(new PemObject("RSA PUBLIC KEY", publicKey.getEncoded())); pemWriter.flush(); pemWriter.close(); return writer.toString(); Now as you can probably tell I'm not sure how to construct the PemObject or if there is an easier way to do this. When using Bouncy Case I used to do this like this

Generating PublicKey from x and y values of elliptic curve point

ぐ巨炮叔叔 提交于 2019-11-30 19:18:33
I am trying to generate a shared secret in my app like this: public static byte[] generateSharedSecret(PrivateKey privateKey PublicKey publicKey) { KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", "SC"); keyAgreement.init(privateKey); keyAgreement.doPhase(publicKey, true); return keyAgreement.generateSecret(); } This is working fine, but the PublicKey I use here should be coming from the backend. The backend just sends me the x and y value of a point on an elliptic curve and now I am supposed to generate the PublicKey from that. But I just can't figure it out! How can I create a

Compare PublicKey object in java

南笙酒味 提交于 2019-11-30 14:44:14
I have two PublicKey object.I want to compare both for equality or to check which is latest object using java security API or bouncy castle API.How can i achieve this? You can use equals if (!key.equals(copyKey)){ System.out.println("not equals!"); } or check the hashcode of the keys if (key.hashCode() != copyKey.hashCode()) { System.out.println("public key hashCode check failed"); } or compare the hex string of the two public keys String encodedKey1 = new String(Hex.encode(key1.getEncoded())); String encodedKey2 = new String(Hex.encode(key2.getEncoded())); if (!encodedKey1.equals(encodedKey2)