cryptography

Random access of encrypted data AES GCM mode

旧街凉风 提交于 2019-12-21 06:29:15
问题 There is a very good example for random access AES CTR mode and it works: Random access InputStream using AES CTR mode in android private static final int AES_BLOCK_SIZE = 16; private static IvParameterSpec calculateIVForOffset(final IvParameterSpec iv, final long blockOffset) { final BigInteger ivBI = new BigInteger(1, iv.getIV()); final BigInteger ivForOffsetBI = ivBI.add(BigInteger.valueOf(blockOffset / AES_BLOCK_SIZE)); final byte[] ivForOffsetBA = ivForOffsetBI.toByteArray(); final

Using Java crypto leads to NoSuchAlgorithmException

*爱你&永不变心* 提交于 2019-12-21 06:24:37
问题 Here's the encryption portion of my code. It compiles fine but fails with that exception at runtime: import java.util.Random; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; ... byte[] salt = new byte[8]; Random rand = new Random(); rand.nextBytes(salt); PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray()); SecretKeyFactory keyFactory = SecretKeyFactory

Java encrypt AES, PHP decrypt AES

♀尐吖头ヾ 提交于 2019-12-21 06:08:28
问题 I was looking for a way to encrypt a string in Java, and decrypt it in PHP. I found this in an answer somewhere on Stackoverflow and I modified it to do the exact opposite. This is my code to encrypt in Java: public static String encrypt(String data, String initialVectorString, String secretKey) { String encryptedData = null; try { SecretKeySpec skeySpec = new SecretKeySpec(md5(secretKey).substring(0, 16).getBytes(), "AES"); IvParameterSpec initialVector = new IvParameterSpec

Generate AES key without password using BouncyCastle

旧巷老猫 提交于 2019-12-21 06:08:22
问题 I need to generate a key to use when encrypting a file symmetrically using AES256/CBC The key itself will be encrypted with RSA public/private so I don't need a password applied. In Java, this seems to be done as follows: SecureRandom random = new SecureRandom(); byte[] keyBytes = new byte[32]; //32 Bytes = 256 Bits random.nextBytes(keyBytes); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); However, SecretKeySpec isn't defined in the C# BouncyCastle library available via NuGet. What's

Reading Private Key in PEM format with LockBox

删除回忆录丶 提交于 2019-12-21 06:06:55
问题 I have to digitally sign a string using the SHA-1 algorithm with RSA using PKCS#1 padding. I have downloaded Turbo Power Lockbox. The private key I have is in PEM format and was created using openssl: openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj "/C=US/ST=CA/L=Mountain View/CN=www.mycompany.com" -keyout myrsakey.pem -out c:\temp\myrsacert.pem Here is what it looks like: -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDFzvqdAEQn9MrSLTNua5SOxshV/8jQIf3qpfunBXa9SVdm4NJw

Reading Private Key in PEM format with LockBox

我们两清 提交于 2019-12-21 06:06:05
问题 I have to digitally sign a string using the SHA-1 algorithm with RSA using PKCS#1 padding. I have downloaded Turbo Power Lockbox. The private key I have is in PEM format and was created using openssl: openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj "/C=US/ST=CA/L=Mountain View/CN=www.mycompany.com" -keyout myrsakey.pem -out c:\temp\myrsacert.pem Here is what it looks like: -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDFzvqdAEQn9MrSLTNua5SOxshV/8jQIf3qpfunBXa9SVdm4NJw

Windows CryptoAPI: CryptSignHash with CALG_SHA_256 and private key from MY keystore

大兔子大兔子 提交于 2019-12-21 05:42:20
问题 I am trying to generate digital signatures on Windows (from XP SP3, but currently testing with Windows 7) with CryptoAPI that will be compatible with the following openssl commands: openssl dgst -sha256 -sign <parameters> (for signing) openssl dgst -sha256 -verify <parameters> (for validation) I want to use a private key from the Windows "MY" keystore for signing. I managed to sign files using the SHA1 digest algorithm by using the following CryptoAPI functions (omitting parameters for

java.lang.IllegalArgumentException: string curve25519 not an OID bouncycastle 1.52

亡梦爱人 提交于 2019-12-21 05:40:53
问题 I'm trying to generate a key pair using the /java bouncy castle 1.52 implementation for curve 25519 what gives me java.lang.IllegalArgumentException: string curve25519 not an OID Here is my code: public KeyPair generateKeys() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("curve25519"); KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC"); g.initialize(ecSpec, new

Elliptic curve point

痴心易碎 提交于 2019-12-21 05:40:17
问题 Presently iam working on a project that uses elliptic curve. Please provide me a solution that determines whether a point is on the elliptic curve or not? and also how to get a point on the elliptic curve 回答1: Checking whether a point is on the elliptic curve is easy. Just check whether your point (x,y) fulfills the equation defining your elliptic curve : y^2 = x^3 + ax + b (remember to perform the calculation in the correct field). Using Bouncycastle you can do it like this: ECCurve curve =

Decrypt Media Files in chunks and play via AVPlayer

筅森魡賤 提交于 2019-12-21 05:32:16
问题 I have a mp4 video file which i am encrypting to save and decrypting to play via AVPlayer. Using CRYPTOSWIFT Library for encrypting/decrypting Its working fine when i am decrypting whole file at once but my file is quite big and taking 100% CPU usage and lot of memory. So, I need to decrypt encrypted file in chunks. I tried to decrypt file in chunks but its not playing video as AVPlayer is not recognizing decrypted chunk data maybe data is not stored sequentially while encrypting file. I have