public-key-encryption

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

iOS SecItemCopyMatching RSA public key format?

点点圈 提交于 2019-12-05 16:13:55
I'm trying to extract a 1024-bit RSA public key from an already generated key pair (two SecKeyRef s), in order to send it over the wire. All I need is a plain (modulus, exponent) pair, which should take up exactly 131 bytes (128 for the modulus and 3 for the exponent). However, when I fetch the key info as a NSData object, I get 140 bits instead of 131. Here's an example result: <30818902 818100d7 514f320d eacf48e1 eb64d8f9 4d212f77 10dd3b48 ba38c5a6 ed6ba693 35bb97f5 a53163eb b403727b 91c34fc8 cba51239 3ab04f97 dab37736 0377cdc3 417f68eb 9e351239 47c1f98f f4274e05 0d5ce1e9 e2071d1b 69a7cac4

Heroku HIPAA Compliance

不羁岁月 提交于 2019-12-05 13:09:33
问题 Is it possible to run apps on Heroku that are HIPAA compliant? More specifically, I need two apps, one that stores member information and another that stores private health information of the members. I intend to encrypt sensitive data using both asymmetric and symmetric key encryption–asymmetric for the keys that link members with their sensitive data on the other app, and symmetric for specific fields in the members app, such as name, email address and phone. My main concern is that anyone

How to do Diffie Hellman Key Generation and retrieve raw key bytes in Java

南楼画角 提交于 2019-12-05 10:29:28
I am writing a test harness in java for an existing program. As part of this i need to generate a Diffie Hellman key pair and pass the public key to the other program in its raw (i.e unencoded bytes) form. I can successfully the key pair using the following code: KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman"); kpg.initialize(512); KeyPair dkp = kpg.generateKeyPair(); However, i cannot seem to retrieve the raw byte value of the keys :-( Calling dkp.getPublic().getEncoded() returns a byte array but its of the Key in an x509 encoded format. Three possible ways forward occur

Java to Objective-C RSA Implementation

坚强是说给别人听的谎言 提交于 2019-12-05 07:08:39
问题 I'm in trouble in implementing RSA encryption and decryption in Objective-C , I made it in Java very simply and now I tried to translate this java code in objc . Here is my java code: public static byte[] encryptRSA(byte[] text, PublicKey key) throws Exception { byte[] cipherText = null; // get an RSA cipher object and print the provider Cipher cipher = Cipher.getInstance("RSA"); // encrypt the plaintext using the public key cipher.init(Cipher.ENCRYPT_MODE, key); cipherText = cipher.doFinal

iPhone Public-Key Encryption SecKeyEncrypt returns error 9809 (errSSLCrypto)

笑着哭i 提交于 2019-12-05 02:52:54
问题 I am trying to use the iPhone's PKI libraries to encrypt a short string (12345678), but I keep getting the error -9809 (i.e. errSSLCrypto) whenever I try to use SecKeyEncrypt. The SecureTransport.h header file describes this error simply as "underlying cryptographic error", which wasn't very meaningful. My code is as follows: - (NSData *)encryptDataWithPublicKey:(NSString *)plainText { OSStatus result = -1; NSData *plainTextData = [plainText dataUsingEncoding:NSASCIIStringEncoding]; size_t

encrypting and decryption large file using rsa in java

偶尔善良 提交于 2019-12-05 02:29:18
问题 I am using RSA algorithm for encryption and decryption of a file with size more than rsa key size. In the code below for encryption, i am reading file content in block-wise and converting into cipher text. Block-size is 32 bytes. FileInputStream fin1 = new FileInputStream(genfile); FileOutputStream fout = new FileOutputStream(seedcipher); byte[] block = new byte[32]; int i; while ((i = fin1.read(block)) != -1) { byte[] inputfile= cipher.doFinal(block); fout.write(inputfile); } fin1.close();

Getting BouncyCastle to decrypt a GPG-encrypted message

跟風遠走 提交于 2019-12-04 11:50:35
How can I get BouncyCastle to decrypt a GPG-encrypted message? I have created a GPG key pair at the CentOS 7 command line using gpg --gen-key . I chose RSA RSA as the encryption types, and I exported the keys using gpg --export-secret-key -a "User Name" > /home/username/username_private.key and gpg --armor --export 66677FC6 > /home/username/username_pubkey.asc I am able to import username_pubkey.asc into a remote Thunderbird client of another email account and successfully send an encrypted email to username@mydomain.com. But when my Java/BouncyCastle code running at mydomain.com tries to

Can a public key have a different length (encryption) than the private key?

孤者浪人 提交于 2019-12-04 11:09:20
问题 I have a 1024 bits private key, and use it to generate a public key. Does that automatically mean that my public key also has 1024 encryption? Or can it be of a lesser encryption size? (512, 256...) PS: What i'm mostly interested in, and talking about, is the size of the modulus ("n") in RSA keys. The size is typically 1024 or 2048 bits. But I'm glad to see that this sparked a discussion, and all this is feeding my interest in cryptography. 回答1: No. The public key in a key pair always matches

PKCS#7 Signin and verify sign

旧时模样 提交于 2019-12-04 09:48:21
问题 I am trying to sign and verify sign using PKCS#7. I am following book beginning cryptography with java . I have written sample code to sign and verify. When i am trying to attach a signature and write it to a file and then trying to verify i am getting exception (Exception is given below ) I want to know how do we write this signed data to a file ? Do i need to share keystore also to second person who will verify the sign? org.bouncycastle.cms.CMSException: message-digest attribute value does