cryptography

Can't get ECDSA signature to validate with public key

∥☆過路亽.° 提交于 2020-01-24 22:12:29
问题 I'm running out of ideas as to why my sample code won't verify the given EC public key, signature and message. I've converted the signature to ASN.1 format which is 70 bytes and the public key is 64 bytes plus uncompressed byte (0x04). I've also tried converting the message to SHA256 hash but that didn't work as well. The publicKey hex value is used to construct a ECPublicKey with prime256v1 curve. The signature is base64 decoded then formatted to ASN.1. I don't see what I could be doing

Use of BigInteger.isProbablePrime() to generate cryptographically secure primes

纵然是瞬间 提交于 2020-01-24 20:41:06
问题 Can you use BigInteger.isProbablePrime() to generate cryptographically secure primes? What certainty is necessary for them to be "secure"? 回答1: I do not hold a degree in crypto, so take this with a grain of salt. You have two major areas of concern here: Your primes need to be unpredictably random. This means that you need to use a source such as SecureRandom to generate your primes. No matter how sure of your primality, if they are predictable, the entire cryptosystem fails to meet its goal.

Simple Affine Cipher Encrpytion Decryption

我只是一个虾纸丫 提交于 2020-01-24 18:55:06
问题 I am writing two functions that encrypt and decrypt messages using an affine cipher. For some reason, my encryption and decryption are off by a few letters. I feel the issue is related to the ASCII numbers not matching the a=0, z=25 format. Could someone please help me figure out what's going on? Cleopatra should encrypt to whkcjilxi , MZDVEZC should decrypt to anthony But instead, I'm getting Cleopatra = ZKNFMLOAL and MZDVEZC = NAGUBAL . main function: int main() { plaintext = "cleopatra";

Is using 2 different hash functions a good way to check for file integrity?

微笑、不失礼 提交于 2020-01-23 06:58:26
问题 I have a website where users can upload their files; these are stored on the server and their metadata recorded in a database. I'm implementing some simple integrity checks, i.e. "is the content of this file now byte-for-byte identical as when it was uploaded?" An example: for content of userfile.jpg , MD5 hash is 39f9031a154dc7ba105eb4f76f1a0fd4 and SHA-1 hash is 878d8d667721e356bf6646bd2ec21fff50cdd4a9 . If this file's content changes, but has the same MD5 hash before and after, is it

Crash casting AndroidKeyStoreRSAPrivateKey to RSAPrivateKey

∥☆過路亽.° 提交于 2020-01-22 15:25:02
问题 I'm following this tutorial: How to use the Android Keystore to store passwords and other sensitive information. It (loosely) ties up with the Google Sample app: BasicAndroidKeyStore. I can encrypt my data using the public key, and I can decrypt on devices running Lollipop. However I have a Nexus 6 running marshmallow and this crashes giving the error: java.lang.RuntimeException: Unable to create application com.android.test: java.lang.ClassCastException: android.security.keystore

Crash casting AndroidKeyStoreRSAPrivateKey to RSAPrivateKey

落花浮王杯 提交于 2020-01-22 15:24:12
问题 I'm following this tutorial: How to use the Android Keystore to store passwords and other sensitive information. It (loosely) ties up with the Google Sample app: BasicAndroidKeyStore. I can encrypt my data using the public key, and I can decrypt on devices running Lollipop. However I have a Nexus 6 running marshmallow and this crashes giving the error: java.lang.RuntimeException: Unable to create application com.android.test: java.lang.ClassCastException: android.security.keystore

Decrypting “SunJCE” AES encrypted data on Android

て烟熏妆下的殇ゞ 提交于 2020-01-22 13:11:30
问题 We need to write some Android code to decrypt some data sent from our server. Our server team gave us some sample decryption code which uses the "SunJCE" provider, which unfortunately doesn't exist on Android. Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); Does anybody know the cleanest way to implement this on Android? If we try this on Android Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); then it looks like some unwanted garbage appears at the end of the

Sign data using private key on client-side (javascript)

做~自己de王妃 提交于 2020-01-22 09:54:28
问题 I know, it looks strange, but I need to sign some data on client-side using javascript only, no ajax backdoor to server-side openssl available. Could someone suggest some client-side solution to sign data using private key? Is it possible? Thanks. 回答1: Found great signing tool. It implements RSA-SHA1 (works perfectly) and RSA-SHA256 (works strange), and allow both to generate signature using private key and to verify signature using certificate. 回答2: I've gone down the same road as you, you

Pass list to AES key generator in PyCrypto

纵饮孤独 提交于 2020-01-22 03:20:11
问题 I'm attempting to generate an AES key with Pycrypto but receive the following error: TypeError: 'list' does not support the buffer interface for the following statement: aescipher = AES.new(mykey, AES.MODE_ECB) mykey , is of type list and contains [1885434739, 825373440, 0, 0] Does anyone know how I can convert mykey into the correct type for the AES.new function? 回答1: You should not supply any kind of list/array when creating an AES key. The raw key bytes are normally supplied using a byte

Elliptic Curve Multiplication Function

时光怂恿深爱的人放手 提交于 2020-01-21 10:00:38
问题 I'm trying to make my own library for the elliptic curve. Some things work, but some others don't. To calculate a public key from a private key, you should multiply the Generator Point with the private key, and you get another point: the public key Point (ECPoint = BigInteger * ECPoint). Now, I have a private key, and I multiply it with the Generator Point of the Secp256k1 curve. I get a a key, but it is not the key I should get. This is my JAVA code: import java.math.BigInteger; public class