question
stringlengths
11
28.2k
answer
stringlengths
26
27.7k
tag
stringclasses
130 values
question_id
int64
935
78.4M
score
int64
10
5.49k
I am looking for a cross platform way to share public keys for ECDSA signing. I had a great thing going from a performance perspective with CngKey and the standard .NET crypto libraries, but then I couldn't figure out how a 33 (or 65) byte public key (using secp256r1/P256) was getting turned into 104 bytes by MS.. Erg...
So I have figured out the format of a CngKey exported in ECCPublicKeyBlob and ECCPrivateKeyBlob. This should allow others to interop between other key formats and CngKey for Elliptcal Curve signing and such. ECCPrivateKeyBlob is formatted (for P256) as follows [KEY TYPE (4 bytes)][KEY LENGTH (4 bytes)][PUBLIC KEY (64 ...
Bouncy Castle
24,251,336
20
Does anyone know of a simple tutorial or sample code of how to sign data in c# using bouncy castle. In Java there are tons of tutorials and samples. I can't find a single example in c#. Does anyone know how to do this?
Okay I could not find any documentation on how to do this. But I ended up figuring it out. I am pasting the full code here so hopefully it can help someone in the future. This class will calculate a RSA signature with a sha1 hash for the provided string and verify it as well. using System; using System.IO; using System...
Bouncy Castle
8,830,510
19
I am trying to use C# to read in a .pem file that contains only a RSA public key. I do not have access to the private key information, nor does my application require it. The file myprivatekey.pem file begins with -----BEGIN PUBLIC KEY----- and ends with -----END PUBLIC KEY-----. My current code is as follows: ...
The following code will read a public key from a given filename. The exception handling should be changed for any production code. This method returns an AsymetricKeyParameter: public Org.BouncyCastle.Crypto.AsymmetricKeyParameter ReadAsymmetricKeyParameter(string pemFilename) { var fileStream = System.IO.File.Op...
Bouncy Castle
11,346,200
19
let me start by saying I'm extremely new to all of this. What I am trying to do is to use gpg from within Java in order to decrypt an encrypted file. What I've done successfully: Had a colleague encrypt a file using my public key and his private key and successfully decrypted it. Went the other way Had another collea...
If anyone is interested to know how to encrypt and decrypt gpg files using bouncy castle openPGP library, check the below java code: The below are the 4 methods you going to need: The below method will read and import your secret key from .asc file: public static PGPSecretKey readSecretKeyFromCol(InputStream in, long k...
Bouncy Castle
14,993,223
19
I'm implementing a factory pattern for 3 different cryptography classes. The factory will determine which one to create and then get a serialized instance of the correct class from a database and return it to the requester. Right now I'm working on serializing the classes to store them in the database. I'm writing one ...
Any Serializer Class need a parameterless constructor because, while deserializing it create an empty new instance, then it copies every public property taken from seialized data. You can easily make the constructor private, if you want to avoid to create it without parameters. EX: public class PgpPublicKey { publi...
Bouncy Castle
15,212,051
19
I have a problem with reading certificate information. I want to read full information using java with bouncycastle library in Android programmatically. Now, i'm just using keytool command in console: >keytool -list -keystore 1.p12 -storetype pkcs12 -v Any suggestions?
I've found solution, the main idea is to cast certificate to x509, then get the SubjectDN and parse values. public class TestClass { public static void main(String[] args) throws Exception { KeyStore p12 = KeyStore.getInstance("pkcs12"); p12.load(new FileInputStream("pkcs.p12"), "password".toCharA...
Bouncy Castle
16,970,302
19
The case: I am maintaining a Java applet which uses the BouncyCastle libraries bcpkix-jdk15on-149.jar, and bcprov-jdk15on-149.jar. Problem is when the applet is run on a JRE version 7_u40 enabled browser. The behavior has changed from version 7_u25 in a way that it always prompts a modal window like "Security prompt fo...
After a lot of search and some post in BC mailing list.... I found the solution, so I drop it here for others who may face that issue: The solution is basically to sign the BC library a second time with my own certificate. The JAR needs the JCA signature in order to be trusted as a cryptography provider, so do not remo...
Bouncy Castle
19,029,575
19
Is it possible to read the RSA private key of format PKCS1 in JAVA without converting to PKCS8? if yes, sample code is appreciated. -----BEGIN RSA PRIVATE KEY----- BASE64 ENCODED DATA -----END RSA PRIVATE KEY-----
Java does not come with out-of-the-box support for PKCS1 keys. You can however use Bouncycastle PEMParser pemParser = new PEMParser(new FileReader(privateKeyFile)); JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC"); Object object = pemParser.readObject(); KeyPair kp = converter.getKeyPair((PEMKe...
Bouncy Castle
41,934,846
19
I'm trying to add BouncyCastle as a security provider on Windows XP Pro so I can use it to add some certs to an Android application per the instructions here. Unfortunately I can't get it to add the provider. I've: Downloaded the provider to C:\Program Files\Java\jre6\lib\ext\. Added C:\Program Files\Java\jre6\lib\ext...
The -providerName option requires a provider name ("BC", in this case), not a class name. An alternative option, -providerClass, does require a class name, and it is useful when the provider isn't registered in the java.security file. When you register a provider "programatically", it is only temporary. Your program m...
Bouncy Castle
5,914,108
18
I'm having issues with Bouncycastle, which only arise when running the :lint task. Generally it seems to be a Java 9 byte-code version 53.0 / ASM version conflict. These are the dependencies: // https://mvnrepository.com/artifact/org.bouncycastle implementation "org.bouncycastle:bcprov-jdk15on:1.64" implementation "org...
As already mentioned this was introduced in Java 9, that Android does not support. You could just use packagingOptions to remove those classes. android { packagingOptions { exclude "**/module-info.class" } } This should not affect actual executed code and should also remove classes for lint checks as ...
Bouncy Castle
60,598,110
18
How do I implement AES encryption with the java bouncy castle library? Example code or a link to example code would be nice :)
If you download the bcprov source, you'll see the class org.bouncycastle.jce.provider.test.AESTest. It shows you how to set up the bouncyCastle provider, create encryption and decryption Cipher objects, set up CipherOutputStreams and call the write methods on those streams. Edit: seems like link is broken. Look here f...
Bouncy Castle
2,435,338
17
I'm developing some cryptography on BlackBerry, and we're working with certificates. We use BouncyCastle Lightweight API instead of RIM api to apply the cryptography, but in the lightweight API PEMWriter doesn't work (Well, it isn't included because it needs some JCE). public RSAPrivateCrtKeyParameters _RSAPrivateKey; ...
You could look into the PEMWriter/PEMReader code of bouncy castle and use their implementation as a reference: PemWriter PemReader
Bouncy Castle
14,750,082
17
We have an application that creates PDFs unsing jasperreports. It also manipulates said PDFs using iText after they have been created. We recently started using encryption on some PDF. That means before the app can handle the PDF after its creation, it has to be decrypted. While attempting to do so using iText's PdfRea...
My best guess is that you have ended up with two different versions of Bouncy Castle on your classpath, and it happened so that the classloader has loaded the superclass from one version and is now trying to load the subclass from the other. The versions are different in that one of them defines a final equals method. ...
Bouncy Castle
17,212,410
17
Normally when I grab an X509Certificate2 out of my keystore I can call .PrivateKey to retrieve the cert's private key as an AsymmetricAlgorithm. However I have decided to use Bouncy Castle and its instance of X509Certificate only has a getPublicKey(); I cannot see a way to get the private key out of the cert. Any ideas...
Akp = Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(this.Certificate.PrivateKey).Private;
Bouncy Castle
3,240,222
16
I'm building a network application that uses BouncyCastle as a cryptography provider. Let's say you have this to generate a keypair: ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("prime192v1"); KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC"); g.initialize(ecSpec, new SecureRandom()); Key...
ECDSA and ECDH are from distinct standards (ANSI X9.62 and X9.63, respectively), and used in distinct contexts. X9.63 explicitly reuses elements from X9.62, including the standard representation of public keys (e.g. in X.509 certificates). Hence, ECDSA and ECDH key pairs are largely interchangeable. Whether a given imp...
Bouncy Castle
4,969,570
16
What's the best way to integrate the Bouncy Castle provider in a Java program? I know I can add it programmatically, by using: import org.bouncycastle.jce.provider.BouncyCastleProvider; ... Security.addProvider(new BouncyCastleProvider()); Or either I can add it to a path in the JRE on my machine. What's the best cho...
In my opinion the adding it as security provider with own code is the best option. This is because it is only project dependent - not system dependent. Add the BouncyCastle jar file(s) to your project and add them to the class-path and that's it. It will work on all systems without need for further manual installation...
Bouncy Castle
6,442,012
16
I have a bunch of root and intermediate certificates given as byte arrays, and I also have end user certificate. I want to build a certificate chain for given end user certificate. In .NET framework I can do it like this: using System.Security.Cryptography.X509Certificates; static IEnumerable<X509ChainElement> Bui...
I've done this in Java a number of times. Given that the API seems to be a straight port of the Java one I'll take a stab. I'm pretty sure when you add the store to the builder, that collection is expected to contain all certs in the chain to be built, not just intermediate ones. So rootCerts and primary should be add...
Bouncy Castle
10,724,594
16
I am looking for an example or tutorial to generate X509 Certificates using BC in Java. A lot of example are having/using deprecated API. I gave a look at BC, but it doesn't show which class does what or no proper documentation/example. Please If any one you are having idea about it, please point me to a tutorial where...
Creation of KeyPairGenerator: private KeyPairGenerator createKeyPairGenerator(String algorithmIdentifier, int bitCount) throws NoSuchProviderException, NoSuchAlgorithmException { KeyPairGenerator kpg = KeyPairGenerator.getInstance( algorithmIdentifier, BouncyCastleProvider.PROVIDER_NAME)...
Bouncy Castle
14,930,381
16
I am developing an application that needs to validate SHA256withECDSAsignatures with the help of secp256r1 (NIST P-256, P-256, prime256v1) public keys. The public keys are generated by a different application at some earlier point in time and stored in my database in hex encoding. The format of the hex string here is e...
The Bouncy Castle example code on elliptic curve key pair Generation and key factories got me pretty close. Once I managed to create a ECDSA key factory and a curve specification for the secp256r1/NIST P-256/P-256/prime256v1 curve I was able to use ECPointUtil.decodePoint to obtain a curve point. I could then generate ...
Bouncy Castle
26,159,149
16
Perhaps my expectations are wrong. I am not an cryptography expert, I'm just a simple user. I have exhaustively tried to make this work with no success so far. Background information: I'm trying to port a Legacy Encryption from Delphi Encryption Compendium which is using Blowfish Engine (TCipher_Blowfish_)with CTS oper...
I assume that CTS and CBC will always have the same result if the input is 8 bits length. Is this just lucky/coincidence or is fundamentally truth? No, this is a false statement. Here is the quote from Wikipedia: Ciphertext stealing for CBC mode doesn't necessarily require the plaintext to be longer than one b...
Bouncy Castle
42,249,867
16
Can anyone show me (or provide a link to) an example of how to encrypt a file in Java using bouncy castle? I've looked over bouncycastle.org but cannot find any documentation of their API. Even just knowing which classes to use would be a big help for me to get started!
What type of encryption do you want to perform? Password-based (PBE), symmetric, asymmetric? Its all in how you configure the Cipher. You shouldn't have to use any BouncyCastle specific APIs, just the algorithms it provides. Here is an example that uses the BouncyCastle PBE cipher to encrypt a String: import java....
Bouncy Castle
2,052,213
15
I've being messing around the C# Bouncy Castle API to find how to do a PBKDF2 key derivation. I am really clueless right now. I tried reading through the Pkcs5S2ParametersGenerator.cs and PBKDF2Params.cs files but i really cant figure out how to do it. According to the research I have done so far, PBKDF2 requires a str...
After hours and hours of going through the code, I found that the easiest way to do this is to take a few parts of the code in Pkcs5S2ParametersGenerator.cs and create my own class which of course use other BouncyCastle API's. This works perfectly with the Dot Net Compact Framework (Windows Mobile). This is the equival...
Bouncy Castle
3,210,795
15
I want to use a self-signed signature for ssl connections. I'm following this post. My problem: After creating the Keystore my integrity-check fails. Keytool-Error: java.io.IOException: KeyStore integrity check failed. I'm still searching but maybe someone can save me some time.
Make sure you are using the right password to open the keystore. I was having this error and turns out I was still using the password from the example code in trusted.load()
Bouncy Castle
13,125,609
15
I'm trying to make an HTTPS connection to a server that has a certificate set to expire in April 2013 and uses GlobalSign as the root certificate. HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); // urlConnection.setSSLSocketFactory(sslSocketFactory); urlConnection.setDoOutput(true); urlCon...
Thanks to various people for their hints on this, there are multiple things that all needed to be correct for it to work. If the HTTPS site's certificate is signed by a trusted root certificate then it will work out of the box without a custom SSLSocketFactory. The trusted root certificates CAN be different to that us...
Bouncy Castle
14,114,480
15
I want to convert - RSA Public Key modulus: 9699c3c4406464638d2b30dbed44ddee485b5f9a3d7491434049440d34eb1759376a8bac0e37cee5c18df69acfc60d7252634fd15c26ab2afa16ca831598381356209acea9cea9467acdbd2a9b6d8e7b38d1baa826b1fbce2c185ba324bd17c9fdd6558eb57a082ca8c37fccaa86d4f9ffdc4e5d4a4a7f8e5f5410f835f98c64776cfc34...
That is easy, you can create an RSAPublicKeySpec using the shown valus in BigInteger format. Then create a public key from it, get the encoded byte array and encode it using base64. The only thing you have to to is to add the "BEGIN" and "END" block and correct the line breaks. KeyFactory f = KeyFactory.getInstance("RS...
Bouncy Castle
20,635,455
15
I am trying to create a self-signed trusted certificate. I am using Bouncy Castle from nuget, and the answer on this question. This is the code on that page: public static X509Certificate2 GenerateSelfSignedCertificate(string subjectName, string issuerName, AsymmetricKeyParameter issuerPrivKey, int keyStrength = 2048)...
static void Main() { //Console.WriteLine(ExecuteCommand("netsh http delete sslcert ipport=0.0.0.0:4443")); var applicationId = ((GuidAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value; var certSubjectName = "TEST"; var sslCert = ExecuteCommand("netsh http show ...
Bouncy Castle
36,712,679
15
I am having trouble mapping the following JDK JCE encryption code to Bouncy Castles Light-weight API: public String dec(String password, String salt, String encString) throws Throwable { // AES algorithm with CBC cipher and PKCS5 padding Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); // ...
This should work for you: public String dec(String password, String salt, String encString) throws Exception { byte[] ivData = toByte(encString.substring(0, 32)); byte[] encData = toByte(encString.substring(32)); // get raw key from password and salt PBEKeySpec pbeKeySpec = new PBEKeySpec(pass...
Bouncy Castle
5,641,326
14
I create a certificate using BouncyCastle var keypairgen = new RsaKeyPairGenerator(); keypairgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024)); var keypair = keypairgen.GenerateKeyPair(); var gen = new X509V3CertificateGenerator(); ...
Just be be verbose, this is the full code to add after creation of X509Certificate2 certificate: RSA rsaPriv = DotNetUtilities.ToRSA(keypair.Private as RsaPrivateCrtKeyParameters); certificate.PrivateKey = rsaPriv; (Which of course can be optimised into one line.)
Bouncy Castle
6,128,541
14
I created an OCSP client using Bouncy castle API. I am having a trouble in finding the Certificate Status (Saying whether its revoked or not) from the OCSP response I get. The value returned from resp.getCertStatus() is always null. This is how I create the OCSP request. private OCSPReq generateOCSPRequest(X509Cer...
Actually, if you take a look at the actual value of CertificateStatus.GOOD, you will see that it is, in fact, null. In other words, resp.getCertStatus() returns null meaning GOOD. So you probably just need to take out that (status != null) check.
Bouncy Castle
15,083,181
14
I have successfully written to public and private key files with OpenSSL format. Files: -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpHCHYgawzNlxVebSKXL7vfc/i hP+dQgMxlaPEi7/vpQtV2szHjIP34MnUKelXFuIETJjOgjWAjTTJoj38MQUWc3u7 SRXaGVggqQEKH+cRi5+UcEObIfpi+cIyAm9MJqKabfJK2e5X/OS7FgAwPjgtDbZO ZxamOrWWL8...
I figured this out. Basically to read a private openssl key using BouncyCastle and C# is like this: static AsymmetricKeyParameter readPrivateKey(string privateKeyFileName) { AsymmetricCipherKeyPair keyPair; using (var reader = File.OpenText(privateKeyFileName)) keyPair = (AsymmetricCipherKeyPair)new Pe...
Bouncy Castle
15,629,551
14
I am trying to create an online database application using PHP for the server and C# form application for the client. On the server I encrypt a simple string using a public RSA key with the PHPSecLib. Then the C# application receives the string and tries to decrypt it using the corresponding private key. The bytes are ...
You need to add a new line between the pre/post encapsulation boundary text and the Base64 data, so: string privateKey = "-----BEGIN RSA PRIVATE KEY-----\r\nXXX\r\n-----END RSA PRIVATE KEY-----"; This is because the pem specification allows for the existence of other textual headers between the two.
Bouncy Castle
33,301,427
14
I need to create a PBKDF2-SHA256 password hash, but am having some trouble. I downloaded the Bouncy Castle repo, but got a bit stuck finding what I was looking for in the Unit Tests. Found some sample code here, but this only does SHA1. The key bit of code is: /// <summary> /// Computes the PBKDF2-SHA1 hash of a passw...
EDIT (Previous answer history removed for brevity) There is now a Bouncy Castle Crypto API NuGet package that can be used. Alternatively, you can get the source directly from GitHub, which will work. I had got the standard Bouncy Castle from NuGet, which had not been updated to 1.8.1 at the time of writing. For the ben...
Bouncy Castle
34,950,611
14
I have the following code which generates a nice self-signed cert, works great, but I'd like to update to the latest BouncyCastle (1.8.1.0) and I'm getting warnings about obsolete usage: var persistedCertificateFilename = "ClientCertificate.pfx"; if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Persiste...
I struggled with this for some time, too. I finally have a solution for this. Let's take one of the errors: 'X509V3CertificateGenerator.Generate(AsymmetricKeyParameter)' is obsolete: 'Use Generate with an ISignatureFactory' You are basically using (i was doing the same thing) the Generate method like this: var certif...
Bouncy Castle
36,942,094
14
I follow this instruction to add bouncycastle: http://www.bouncycastle.org/wiki/display/JA1/Provider+Installation but I have still one problem. Sometimes when I redeploy my application this provider isnt found so then my application throw exception. This problem occurs just one per 100 redeploy (maybe less). When I res...
You probably got a NoClassDefFoundError. This is a known issue with JSSE implementations. Here is the scenario: Your container loads bouncy castle classes in an application specific ClassLoader The provider instance you create depends on that classes and so on that ClassLoader Then the provider is registered into JRE ...
Bouncy Castle
10,379,799
13
I'm stuck at the creation of an SSLContext (which I want to use to instantiate an SSLEngine to handle encrypted transport via the java-nio): The code String protocol = "TLSv1.2"; Provider provider = new BouncyCastleProvider(); Security.addProvider(provider); sslContext = SSLContext.getInstance(protocol,provider.getNam...
I know this is kind of an old question, but I needed an answer (so I am creating one): [Is it possible to] create an SSLContext instance using a Bouncy Castle provider [?] No Why not? Debugging this line of code: Provider [] providers = Security.getProviders(); the default SunJSSE version 1.7 implements the followi...
Bouncy Castle
23,906,736
13
I am trying to determine the best method for code-signing an executable using Bouncy Castle, managed code, or un-managed code from C#. Since CAPICOM is now deprecated, I imagine one of the SignerSign methods from mssign32.dll is the best way to go if it needs to be done unmanaged. This answer (https://stackoverflow.co...
As far as I can tell, SignSigner and SignSignerEx are available as of Windows XP, which is the oldest operating system I care to support. Because I do not need to worry about Windows App Store publication, this answer is limited to SignSigner and SignSignerEx, although the import for SignSignerEx2 is very similar to S...
Bouncy Castle
26,344,271
13
I try to use Jasypt with Bouncy Castle crypro provides (128Bit AES) in a Spring Application to decrypt entity properties while saving them with Hibernate. But I always get this org.jasypt.exceptions.EncryptionOperationNotPossibleException when try to save the entrity. org.jasypt.exceptions.EncryptionOperationNotPossibl...
Jasypt is designed to be used with JCE providers, the terminology that this project uses on its web may be confusing you since there is the follow sentence: Open API for use with any JCE provider, and not only the default Java VM one. Jasypt can be easily used with well-known providers like Bouncy Castle From thi...
Bouncy Castle
30,278,104
13
We have a Java application where a job is scheduled to run every 5 minutes. In that job, there is a security component that does the following every time it is executed: java.security.Security .addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); My questions are: Is it required to add t...
According to addProvider's javadoc: Returns: the preference position in which the provider was added, or -1 if the provider was not added because it is already installed addProvider already checks if the provider is installed, so, even if you have multiple calls across your application, it will just be added once. ...
Bouncy Castle
45,197,948
13
Is Bouncy Castle API Thread Safe ? Especially, org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher org.bouncycastle.crypto.paddings.PKCS7Padding org.bouncycastle.crypto.engines.AESFastEngine org.bouncycastle.crypto.modes.CBCBlockCipher I am planning to write a singleton Spring bean for basic level cryptography ...
It really does not matter if the API/Code is thread safe. CBC encryption in itself is not thread safe. Some terminology - E(X) = Enctrypt message X D(X) = Dectrypt X. (Note that D(E(X)) = X) IV = Initialization vector. A random sequence to bootstrap the CBC algorithm CBC = Cipher block chaining. A really simple CBC i...
Bouncy Castle
49,473
12
This unit test is failing: public void testDigest() throws NoSuchAlgorithmException { String hashExpected = "150a14ed5bea6cc731cf86c41566ac427a8db48ef1b9fd626664b3bfbb99071fa4c922f33dde38719b8c8354e2b7ab9d77e0e67fc12843920a712e73d558e197"; MessageDigest md = new MessageDigest(); String hashActual = new ...
The value you're expecting is a Hex-encoded value. You're creating a String based on the raw bytes, which won't work. You should use the standard Java Crypto API whenever possible instead of BouncyCastle specific APIs. Try the following (the Hex library comes from commons-codec): Security.addProvider(new BouncyCastleP...
Bouncy Castle
2,208,374
12
I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java it says we have to import and add the provider during runtime by the following code import org.bouncycastle.jce.provider.BouncyCastleProvider; Security.addProvider(new BouncyCastleProvider()); error - The import or...
None of these answers is accurate in 2021 or even several years prior. Neither using Spongy Castle nor recompiling Bouncy Castle with a different package namespace are necessary since the package name conflicts on Android platform were resolved in Honeycomb (unless you still support pre-honeycomb devices). For details ...
Bouncy Castle
2,584,401
12
I am trying to generate X509 certificates with bouncycastle 1.46, with the code below. The issue I have is that when a certificate is written in a JKS and then reread, the DNs are reversed. For instance, if I run the code below, I get the following output: CN=test,O=gina CN=test,O=gina CN=test,O=gina O=gina, CN=test D...
This may be a bit simpler. At least in BC 1.48+, you can construct the X500Name thusly, and the OIDs will be ordered in the expected way (or at least, the way you specify them): final X500Name subject = new X500Name(RFC4519Style.INSTANCE, "CN=test,O=gina");
Bouncy Castle
7,567,837
12
Hy Guys! I'm trying to create x.509 certificate using bouncycastle, which should be signed by another certificate and store it PEM base 64 format. I've already have self-signed certificate (public and private key). Now I want to create new one and sign it with existing self-signed certificate. KeyPairGenerator keyPairG...
I was able to find solution. Actually code works as expected. I didn't see chain of certificates because my caRoot certificate wasn't added to the trusted store. After I add my sel-signed certificate to the trusted root certified centers I see the whole certification chain as I expected.
Bouncy Castle
15,142,577
12
I have been trying to put together an in-memory public-key encryption infrastructure using OpenPGP via Bouncy Castle. One of our vendors uses OpenPGP public key encryption to encrypt all their feeds, and requires us to do the same, so I'm stuck with the technology and the implementation. So now I'm coding an OpenPGP ...
OK, I managed to get this working. There were several problems with this implementation. One problem was that certain things had to be done in order. Here is what seems to need to happen: The raw data needs to be put into a PgpLiteralData object The literal data needs to be encrypted. The encrypted data needs to be...
Bouncy Castle
18,856,937
12
I'm currently implementing password hashing using scrypt. I have already found a nice scrypt implementation on GitHub. To my surprise I have also discovered a scrypt implementation in the Bouncy Castle library. The class is not documented, Wikipedia didn't mention Bouncy Castle as scrypt implementation provider and I h...
So that people don't have to go to an external site for an answer: Make sure bouncy castle jars are on your build path Import SCrypt like so: import org.bouncycastle.crypto.generators.SCrypt; Use SCrypt like so: byte[] sCryptHash = SCrypt.generate(plaintext.getBytes(), salt.getBytes(), cpuDifficultyFactor, memoryDiff...
Bouncy Castle
22,226,867
12
I've been trying to use the BouncyCastle library to do PGP encryption/decryption. I have some code that I need to modify to use streams only - no files. I tried removing the PgpUtilities.WriteFileToLiteralData() and then making it return a stream, but it didn't work (output stream was empty). To be more clear here is w...
I got it working. The code uses byte[] for input and output of both decryption and encryption - no files. Here is the full class: class PGP { public PGP() { } /** * A simple routine that opens a key ring file and loads the first available key suitable for * encryption. * * @param in * @retu...
Bouncy Castle
25,441,366
12
I noticed that there are two bouncycastle provider libraries for Java; bcprov and bcprov-ext. How do they differ? How do I choose which to use?
bcprov is typically the library you want. bcprov-ext includes some obscure crypto algorithms that haven't been part of the main release since v1.4.0. This is briefly explained on the latest releases page: From release 1.40 some implementations of encryption algorithms were removed from the regular jar files at the re...
Bouncy Castle
29,211,582
12
Is there any way to convert a Org.BouncyCastle.X509.X509Certificate to System.Security.Cryptography.X509Certificates.X509Certificate2? The inverse operation is easy, combining Org.BouncyCastle.X509.X509CertificateParser with System.Security.Cryptography.X509Certificates.X509Certificate2.Export().
Easy!! using B = Org.BouncyCastle.X509; //Bouncy certificates using W = System.Security.Cryptography.X509Certificates; W.X509Certificate2 certificate = new W.X509Certificate2(pdfCertificate.GetEncoded()); And now I can validate certificate chain in the server: W.X509Chain ch = new W.X509Chain(); ch.ChainPolicy.Revoca...
Bouncy Castle
8,136,651
11
I am trying to debug an issue with bouncy castle 1.47. I can find a debug jar for 'bcprov' but not for {org.bouncycastle:bcpkix-jdk15on:1.47:jar}. Is there any other place to download bcpkix-jdk15on-1.47.jar with debug information? or Is there a tool that can generate line numbers from a jar (containing .class files) w...
I have managed to generate jar with debug information from bouncy castle source. in ROOT_SRC/bc-build.properties, set release.debug to true release.suffix: 147 release.name: 1.47 release.debug: true The build expects mail (sun implementation) and junit jars to be available in classpath. I have put them on to jdk/jre/l...
Bouncy Castle
12,894,129
11
I am using RESTEasy encryption. For that I have to generate x.509 certificate by the Java 'keytool' command-line interface. Please help me Thank you
This is the command to generate self signed certificates. All in one line keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048 When you run this command, it will ask you for the details of the signatory. These will be the details of your organiza...
Bouncy Castle
16,851,903
11
I'm pretty new to BouncyCastle and pgp. I've seen many articles and samples on the internet. Almost every encryption sample contains the code snipped below if (armor) out = new ArmoredOutputStream(out); It seems that my local test passed with both armor and none-armor. I googled around but found few useful an...
ArmoredOutputStream uses an encoding similar to Base64, so that binary non-printable bytes are converted to something text friendly. You'd do this if you wanted to send the data over email, or post on a site, or some other text medium. It doesn't make a difference in terms of security. There is a slight expansion of ...
Bouncy Castle
24,358,996
11
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 keyAgreemen...
It's actually quite simple! But you need one more thing besides the x and y values. You also need an ECParameterSpec! The ECParameterSpec describes the elliptic curve you are using and your app has to use the same ECParameterSpec as your backend does! With the x and y values you can create an ECPoint instance and toge...
Bouncy Castle
30,116,758
11
I was attempting to generate a public ECDSA key from a private key, and I haven't managed to find much help on the internet as to how to do this. Pretty much everything is for generating a public key from a public key spec, and I don't know how to get that. So far, this is what I've put together: public void setPublic(...
So after a while, I figured out a solution and decided to post it in case anyone else has the same issue as me: KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "BC"); ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256k1"); ECPoint Q = ecSpec.getG().multiply(((org.bouncycastle.jce.inte...
Bouncy Castle
49,204,787
11
I am wondering if this is a correct way to create PrivateKey object in Java from HEX string from this website: https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html Create a BigInteger from a HEX String: BigInteger priv = new BigInteger(privateKeyFromSite, 16); And pass to this method: import java.math.BigInteger;...
Yes it's correct, an EC private key is just a number. If you print out your PrivateKey, you'll see the X and Y coordinates of the corresponding public key. For example, let's say the following key pair was generated (secp256r1): EC Private Key: 1b9cdf53588f99cea61c6482c4549b0316bafde19f76851940d71babaec5e569 EC Public...
Bouncy Castle
52,004,341
11
I need to code this openssl-sign-instruction in java. openssl dgst -sha256 -binary -out "signaturefile".sig -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -sign "privatekey".pem "file2sign" This instruction comes from Bundeszentralamt für Steuern (BZSt) - ELMA-File-Upload. Bitte stellen Sie die Signaturerst...
I edited my question with the correct algorithm to create the signature with java bouncycastle. Signature signatureSHA256Java = Signature.getInstance("SHA256withRSA/PSS"); signatureSHA256Java.setParameter(new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, 32, 1)); You can verify the java generated sign...
Bouncy Castle
53,728,536
11
I'm trying to generate a certificate self-signed by a KeyPair stored in Azure KeyVault. My end result is a certificate with an invalid signature: Generating the certificate parameters: DateTime startDate = DateTime.Now.AddDays(-30); DateTime expiryDate = startDate.AddYears(100); BigInteger serialNumber...
The problem is that the signature being returned by key vault is in a "raw" (64-byte) format, where the first 32 are R and the last 32 are S. For this to work in bouncycastle, your GenerateSignature method needs to return this in an ASN.1 formatted byte array, which in the end will be somewhere between 70 and 72 bytes....
Bouncy Castle
63,268,843
11
I'm familiar with basic cryptography in java But have zero experience in bouncycastle, Recently I came across a requirement that needs to read an encrypted and signed file from FTP. The sender has directed me to use bcfips ebook for reading those encrypted and signed files. I went through the download page of the bounc...
First of all, bcprov contains the Java security provider as well as the "lightweight API". Quite often this library is simply referred to as "Bouncy Castle", shortened to the acronym "BC" as provider name in Java. These providers provide SPI's (service provider implementations) or implementation classes that allow spec...
Bouncy Castle
73,010,512
11
In Java I have a ECDH public Key that I am sending as a byte array. Once I have received the byte array how can I turn it back into a public key? I am using Bouncy Castle but a Java solution would be just as useful. Thanks
When you got the encoded key, assuming you used the default "[your keyPair].getPublic().getEncoded()" method, this will work. X509EncodedKeySpec ks = new X509EncodedKeySpec(pubKeyByteString.toByteArray()); KeyFactory kf; try { kf = java.security.KeyFactory.getInstance("ECDH"); } catch (NoSuchAl...
Bouncy Castle
2,218,879
10
I have a block of ciphertext that was created using the JCE algorithim "PBEWithSHA256And256BitAES-CBC-BC". The provider is BouncyCastle. What I'd like to do it decrypt this ciphertext using the BouncyCastle lightweight API. I don't want to use JCE because that requires installing the Unlimited Strength Jurisdiction Pol...
I tried this and it seemed to work. Borrowed heavily from the BC class org.bouncycastle.jce.provider.test.PBETest private byte[] decryptWithLWCrypto(byte[] cipher, String password, byte[] salt, final int iterationCount) throws Exception { PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(new ...
Bouncy Castle
2,957,513
10
I've been pouring through article after article on x509 cert creation, signing, etc. but I've yet to find a solution to my problem - wondering if anyone can point me in the right direction because I'm thoroughly confused at this point. Here's what I'm trying to do: For the client app: Generate a public/private keypair...
You can use the Bouncycastle C# library. Documentation is not good, but I believe it is not too difficult to work with. You can first go to the Javadocs for the java version of the library; the java and C# version are very similar. Secondly, look at the source code, as it is relatively easy to read. The class you want ...
Bouncy Castle
4,637,543
10
Okay, I'll say now that I know very little about Java. I was given the Bouncy Castle Jar and told that would contain what I needed to do this assignment. The Jar file is bcprov-jdk15on-147.jar. I'm also doing this on a Unix machine maintained by my school, so I can't go in and play with all of the Java files. When I co...
Type this for running the program: java -classpath bcprov-jdk15on-147.jar:. encrypt That's because your program also needs to have any libraries it uses as part of the classpath at the time of running, not only at compile time.
Bouncy Castle
10,134,161
10
I'm trying to generate cryptographically secure random numbers using Java and using the following code section to create a SecureRandom object to view its provider and algorithm: Provider prov=new org.spongycastle.jce.provider.BouncyCastleProvider(); Security.insertProviderAt(prov, 1); SecureRandom sr=new SecureRandom...
Bouncy Castle does provide a set of Pseudo Random Number Generators (PRNGs). There are many names for PRNG's; NIST calls them Deterministic Random Bit Generators (DRBGs). They are however only available in the "Lightweight" API of Bouncy Castle, in the package org.bouncycastle.crypto.prng. However, Bouncy Castle is a s...
Bouncy Castle
10,259,780
10
Here is my implementation of a AES 256 encrypt and decrypt, developed with the native library of JDK 5: public static String encrypt(String key, String toEncrypt) throws Exception { Key skeySpec = generateKeySpec(key); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); ...
You would either use Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES", "BC"); or else Cipher cipher = Cipher.getInstance("AES", new BouncyCastleProvider()); That said, Cipher.getInstance("AES") uses Electronic Codebook, which is insecure. You either want Cipher Block Chainin...
Bouncy Castle
15,925,029
10
I need to export and import generated certificates with private keys to and from byte arrays, and I don't have any problems unless I use .NET framework 4.0 and 4.5. I'm generating self-signed certificates with BouncyCastle library and then converting them to .NET format (X509Certificate2 object). Unfortunately with the...
I haven't noticed that CspKeyContainerInfo.CspParameters.KeyContainerName is empty after key creation in .NET 4.0 and .NET 4.5, but it was autogenerated in .NET 3.5. I've set a unique name for container and now I'm able to export the private key. public static AsymmetricAlgorithm ToDotNetKey(RsaPrivateCrtKeyParameters ...
Bouncy Castle
16,419,911
10
We have an application that uses Bouncy Castle to encrypt data using PBEWITHSHA256AND128BITAES-CBC-BC algorithm. It works fine on Ubuntu running OpenJDK 1.7. But when when we move it to RedHat 6.4 also running OpenJDK 1.7, we get the following exception: java.security.NoSuchAlgorithmException Any thoughts on what cou...
Do you have the BouncyCastle provider JAR (e.g. bcprov-jdk15on-149.jar) in your classpath? I tested your scenario with a minimal CentOS 6.4 (64-bit) installation, OpenJDK 1.7 and BouncyCastle 1.49, and found no issues with it. I placed the JAR in the JRE lib/ext directory: /usr/lib/jvm/java-1.7.0-openjdk.x86_64/jre/lib...
Bouncy Castle
16,857,723
10
I am trying to implement ECDSA (Elliptic Curve Digital Signature Algorithm) but I couldn't find any examples in Java which use Bouncy Castle. I created the keys, but I really don't know what kind of functions I should use to create a signature and verify it. public static KeyPair GenerateKeys() throws NoSuchAlgorit...
owlstead is correct. And to elaborate a bit more, you can do this: KeyPair pair = GenerateKeys(); Signature ecdsaSign = Signature.getInstance("SHA256withECDSA", "BC"); ecdsaSign.initSign(pair.getPrivate()); ecdsaSign.update(plaintext.getBytes("UTF-8")); byte[] signature = ecdsaSign.sign(); And to verify: Signature ec...
Bouncy Castle
18,244,630
10
I wanted to code from this answer but i have error The import org.bouncycastle.openssl cannot be resolved The import org.bouncycastle.openssl cannot be resolved and i have no idea how coudl i repair this becouse other bouncycastle libs are detected correctly. I will be grateful for any ideas whats wrong. Im using ecli...
In addition to the provider (a.k.a. bcprov) and lightweight API, you also need the PKIX API, which provides the openssl package. Either download bcpkix-jdk15on-150.jar from BC downloads page (direct link) and drop it in the same directory of bcprov or add it to your maven dependencies with its coordinates: <dependency>...
Bouncy Castle
24,161,146
10
I'm working on a Java program to decrypt a TLS 1.2 Session which is using the TLS_RSA_WITH_AES_128_GCM_SHA256 cipher. I recorded a test session using wireshark. The Master Secret is known. No. Time Protocol Length Info 4 0.000124000 TLSv1.2 166 Client Hello 6 0.000202000 TLSv1.2 107...
GCM mode computes MAC from message, associated data and public nonce, you covered it very well. I think you are using wrong length, it should be plaintext length before encrypting and appending MAC. Try 45 - 8 (explicit nonce) - 16 (MAC) = 21.
Bouncy Castle
28,198,379
10
I created public and private PGP keys using org.bouncycastle.openpgp.PGPKeyRingGenerator. After making a change suggested by GregS, the public key is a .asc file, and the private key is a .skr file. I need to distribute the public key at first to Thunderbird users, and then later to users of Outlook and other email c...
I'll try to address these points one by one: Java bouncycastle keyring generation The Java code does work and produces a usable keyring pair. I have tested it with different emails and different pass codes with no problems. I have had a 3rd party send me an email using the public key and successfully decrypted it wit...
Bouncy Castle
28,245,669
10
How can one decompile Android DEX (VM bytecode) files into corresponding Java source code?
It's easy Get these tools: dex2jar to translate dex files to jar files jd-gui to view the java files in the jar The source code is quite readable as dex2jar makes some optimizations. Procedure: And here's the procedure on how to decompile: Step 1: Convert classes.dex in test_apk-debug.apk to test_apk-debug_dex2jar....
Dex
1,249,973
782
Since updating to ADT 14 I can no longer build my project. It was building fine prior to updating. The error: [2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array; [2011-10-23 16:23:29 - myProj] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex fi...
I had the same problem, quite weird because it was happening only when using Eclipse (but it was OK with Ant). This is how I fixed it: Right click on the Project Name Select Build Path -> Configure Build Path In Java Build Path, go to the tab Order and Export Uncheck your .jar library Only sometimes: In Order and Exp...
Dex
7,870,265
398
I have seen various versions of the dex erros before, but this one is new. clean/restart etc won't help. Library projects seems intact and dependency seems to be linked correctly. Unable to execute dex: method ID not in [0, 0xffff]: 65536 Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, ...
Update 3 (11/3/2014) Google finally released official description. Update 2 (10/31/2014) Gradle plugin v0.14.0 for Android adds support for multi-dex. To enable, you just have to declare it in build.gradle: android { defaultConfig { ... multiDexEnabled true } } If your application supports Android ...
Dex
15,209,831
346
I have Android Studio Beta. I created a new project with compile my old modules but when I tried launching the app it did not launch with the message: Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex ...
I tried all the above and none of them helps. finally, I find this work for me: app/build.gradle: android { defaultConfig { multiDexEnabled true } }
Dex
46,267,621
325
I have some questions regarding dex files What is a dex file in Android? How does dex work for Android? How are they used in debugging an Android app? Are they similar to java class files? I need specific information please help on this and any real examples are welcome!
About the .dex File: One of the most remarkable features of the Dalvik Virtual Machine (the workhorse under the Android system) is that it does not use Java bytecode. Instead, a homegrown format called DEX was introduced and not even the bytecode instructions are the same as Java bytecode instructions. Compiled Android...
Dex
7,750,448
235
When compiling a specific Android project, and only on my Windows machine, I get a java.nio.BufferOverflowException during from dex. The problem occurs both when using Eclipse and when using Ant. The output when using Ant is: ... [dex] Pre-Dexing C:\MyProject\libs\android-support-v4.jar -> android-support-v4-5f5341d3...
No need to downgrade the build tools back to 18.1.11, this issue is fixed with build tools 19.0.1. If you can't use 19.0.1 for some reason then: Make sure that the value of android:targetSdkVersion in AndroidManifest.xml matches target=android-<value> in project.properties. If these two values are not the same, buildin...
Dex
19,727,915
174
Are the users able to convert the apk file of my application back to the actual code? If they do - is there any way to prevent this?
First, an apk file is just a modified jar file. So the real question is can they decompile the dex files inside. The answer is sort of. There are already disassemblers, such as dedexer and smali. You can expect these to only get better, and theoretically it should eventually be possible to decompile to actual Java ...
Dex
3,122,635
95
I don't know why but it's impossible to launch my app on my mobile this morning. I get this error message: Cannot fit requested classes in a single dex file. Try supplying a main-dex list. # methods: 68061 > 65536 Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. Try supplying a main-dex list...
In root build.gradle file do something like: dependencies { // ... implementation 'androidx.multidex:multidex:2.0.1' } android { defaultConfig { // ... multiDexEnabled true } } More details here: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list....
Dex
51,341,627
95
I have a rather large Android app that relies on many library projects. The Android compiler has a limitation of 65536 methods per .dex file and I am surpassing that number. There are basically two paths you can choose (at least that I know of) when you hit the method limit. 1) Shrink your code 2) Build multiple dex f...
It looks like Google has finally implementing a workaround/fix for surpassing the 65K method limit of dex files. About the 65K Reference Limit Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The ...
Dex
15,471,772
90
Actually I was trying to extract code of a .apk file called cloudfilz.apk and wanted to manipulate in its source code so I followed the steps given below:- make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg: rename from filename.apk to filename.apk.zip) and ...
Note: All of the following instructions apply universally (aka to all OSes) unless otherwise specified. Prerequsites You will need: A working Java installation A working terminal/command prompt A computer An APK file Steps Step 1: Changing the file extension of the APK file Change the file extension of the .apk fil...
Dex
7,888,102
82
I'm trying the new MultiDex Support on my app and so far I've managed to compile my app correctly, but when running it, I get the following exception: java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android....
The solution didn't help me because I was using jetpack version ie androidx. libraries. Followed official doc. And I had to change name to androidx....Multidex. <application android:name="androidx.multidex.MultiDexApplication" > ... </application> Hope It helps other people looking for adding multi...
Dex
26,763,702
65
I am going to learn a little bit about Dalvik VM, dex and Smali. I have read about smali, but still cannot clearly understand where its place in chain of compilers. And what its purpose. Here some questions: As I know, dalvik as other Virtual Machines run bytecode, in case of Android it is dex byte code. What is s...
When you create an application code, the apk file contains a .dex file, which contains binary Dalvik bytecode. This is the format that the platform actually understands. However, it's not easy to read or modify binary code, so there are tools out there to convert to and from a human readable representation. The most co...
Dex
30,837,450
61
I'm having troubles trying to compile an Android application with Gradle 0.5.+ and Android Studio, using SimpleXML. This is the error: Gradle: Execution failed for task ':MyApplication:dexDebug'. > Failed to run command: /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/dx --dex --output <REALLY_LONG_S...
You need to also exclude stax-API. implementation('org.simpleframework:simple-xml:2.7.+'){ exclude module: 'stax' exclude module: 'stax-api' exclude module: 'xpp3' }
Dex
18,084,285
59
I have a .dex file, call it classes.dex. Is there a way to "read" the contents of that classes.dex and get a list of all classes in there as full class names, including their package, com.mypackage.mysubpackage.MyClass, for exmaple? I was thinking about com.android.dx.dex.file.DexFile, but I cannot seem to find a met...
Use the command line tool dexdump from the Android-SDK. It's in $ANDROID_HOME/build-tools/<some_version>/dexdump. It prints a lot more info than you probably want. I didn't find a way to make dexdump less verbose, but dexdump classes.dex | grep 'Class descriptor' should work.
Dex
11,343,388
53
In an android project, build.gradle file, I have been through this line dexOptions{ javaMaxHeapSize "4g" } I would like to know the exact purpose of this javaMaxHeapSize and what does that 4g means. What are other values I can give ?
As it mentioned in the answer above, it is just an option to specify the maximum memory allocation pool for a Java Virtual Machine (JVM) for dex operation. And it's the same, as to provide to java the -xmx argument. Due to it's source codes from here, it's setter look like: if (theJavaMaxHeapSize.matches("\\d+[kKmMgGtT...
Dex
33,750,404
51
I made: In "Settings"->"Android SDK"->"SDK Tools" Google Play services is checked and installed v.46 Removed folder /.gradle "Clean Project" "Rebuild Project Error is: Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: java.lang.RuntimeException:...
Go to <project>/app/ and open build.gradle file Add the following line to the defaultConfig and dependencies sections android { ... defaultConfig { ... multiDexEnabled true // ADD THIS LINE } } ... dependencies { ... implementation 'com.android.support:multidex:1.0.3' // ADD THIS LINE }
Dex
46,977,267
42
I am getting the following error when I compile my app: [2014-05-07 21:48:42 - Dex Loader] Unable to execute dex: Cannot merge new index 65536 into a non-jumbo instruction! I am at the point that if I declare a new method anywhere in my package, I get this error. If I don't, the app compiles. I would like to know what...
Your error is for the amount of strings (methods, members, etc) in a single dex file. You need to compile you app using jumbo in dex with: dex.force.jumbo=true in project.properties This increment the limit for strings in a dex files. And your project will probably compile. Also with jumbo set, the is another limit o...
Dex
23,527,218
36
I'm working on android app that's running up against the dex method count limit. Is there a simple way to show the method count grouped by package? I can get the total method count, but my app has multiple components and I'm trying to figure out which component is the biggest contributor to this.
I've written a dex-method-counts tool that outputs per-package method counts faster and more accurately than the smali-based tools referenced in JesusFreke's answer¹. It can be installed from https://github.com/mihaip/dex-method-counts. [1] that script disassembles the .dex and re-assembles it by package, but this mea...
Dex
17,094,094
34
Can i have the count of all methods used in a jar file . My APK uses certain external JARS and there are a number of classes around hundred to be precise. I have used decompilers like dex2jar JAD and others to name a few ,but they all seem to show methods only in particular class file. Is there a way i can get a total ...
You can convert the jar to a dex file, and then pull the number of method references out of the header. It is stored as an unsigned little endian integer, at offset 88 (0x58). dx --dex --output=temp.dex orig.jar cat temp.dex | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"' Keep in mind that this is the number of uni...
Dex
14,023,397
33
In Android systems or development enviroments, what are the differences between AAR, JAR, DEX, and APK files? What is the purpose of each one? AFAIK, JAR are just like a collection of .class files (like in Java). AAR are JAR files + resources. But what's its usage case? To be used to distribute development libraries f...
JAR (Java Archive) JAR is a package file format designed for distribution of Java application on its platform. It contains compiled Java class files + some more files like MANIFEST. Basically it is just an ZIP archive with some restrictions. DEX (Dalvik Executable) DEX is binary file format, so it is compiled. We could...
Dex
33,533,370
33
Okay, now i'm really stuck here. I don't know what to do, where to go or ANYTHING! I have been trying to uninstall, reinstall, both SDK and Eclipse-versions, trying to Google this out, but nu-uh... Nothing!!! I CAN run my app in emulator, but i cant EXPORT it... [2011-10-07 16:35:30 - Dex Loader] Unable to execute dex...
There is a file in bin/dexedLibs The same file exists in libs Delete it in libs and it should work. For me it was the android-support-v4.jar. Hope this helps
Dex
7,688,828
29
I am wondering, if there is any way, how to set skip packaging and dexing in IntelliJ IDEA like in Eclipse and ADT. There is Additional VM Options field in Android DX Compiler section in IntelliJ Preferences, maybe this could be a way, how to set it. I would also appreciate another tips, how to speed up IntelliJ Andro...
I'm using IntelliJ 12. I've won time deploying and running Android apps enabling IntelliJ to "Make project automatically". To enable it, just go to Preferences -> Compiler and check "Make project automatically". In the same window check "Compile independent modules in parallel". Enabling "Make project automatically" al...
Dex
13,335,674
28
I'm trying to run instrumentation test cases but getting the below error while dex conversion UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded at com.android.dx.command.dexer.Main.processAllFiles(Main.java:494) at com.android....
Let's first understand the problem: On pre-Lollipop devices, only main dex is being loaded by the framework. To support multi-dex applications you have to explicitly patch application class loader with all the secondary dex files (this is why your Application class have to extend MultiDexApplication class or call Mul...
Dex
32,721,083
28
I'm trying to create a test example where I've the contents of a TextView is set to the contents of a file stored in the IPFS. I'm using this repository for my functions: https://github.com/ipfs/java-ipfs-api I keep getting what appears to be a multidex error despit enable multidex in multiple places: defaultConfig { ...
Just experienced the same problem, it is because some library use Java 8 features, in your case it should be java-ipfs-api. To solve the problem, configure Android Gradle Plugin to support Java 8 by adding the following code to your build.gradle file, be sure to use latest Android gradle plugin: android { ... ... c...
Dex
50,121,367
28
My team and I have inherited a large Android project from another team. The whole application with all the included libraries is reported to have around 35000 methods. We now have the task to implement a new service in the app where we need to use Protocol Buffers. The problem is that the generated .jar file with all t...
You can use another DEX file. This is how you do it: http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
Dex
15,436,956
27
I updated Android Studio to the latest version, and let it "fix the project" and the like - but now my project does not compile, gives me FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:dexDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to ru...
The error means you have reached maximum method count in your app. That does include any libraries that you use for your project. There are two ways to tackle the issue: Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. For...
Dex
27,377,080
27
Dalvik has this well-known limitation on the number of methods it can have in a single .dex file (about 65,536 of them). My question is whether inherited (but not overridden) methods count against this limit or not. To make things concrete, suppose I have: public class Foo { public int foo() { return 0; } } pu...
An inherited but not overridden method only counts against the method limit if it is ever referenced (called). In your example, let's say you have the following piece of code public class main { public static void main(String[] args) { Foo foo = new A(); foo.foo(); } } In this case, you are ref...
Dex
17,730,815
25
I'm not totally sure what the difference is between setting dex option "jumbomode" to true vs adding multidex support. Setting jumbo mode to true or multidex to true seems to fix the problem below AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"...
Jumbo Mode, when reading https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html, the const-string/jumbo is the jumbo mode for string. It is about the opcode such that "op vAA, string@BBBBBBBB" versus "op vAA, string@BBBB", 32 bits versus 16 bit. Multi Dex is to allow to load classes from more than one dex...
Dex
30,495,212
25
Adding Multi dex support with the support v4-r21 using gradle def (https://plus.google.com/+IanLake/posts/JW9x4pcB1rj) apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "20.0.0" defaultConfig { applicationId "info.osom.multidex" minSdkVersion 19 targetSdkVersion 19 ...
Add multi-dex shadow as your dependency: testCompile "org.robolectric:shadows-multidex:3.0" This will mock MultiDex.install call and do nothing, since there are no dex in Robolectric
Dex
26,512,170
21
I have been getting this strange error the whole of today - anyone know what is going wrong here? As far as I know, I have been using the multidex library correctly (the below is from the app.gradle file): defaultConfig { applicationId "com.example.simon" minSdkVersion 14 targetSdkVersion 23 versionCode...
After googling for a while, I found the problem was that not enough heap was allocated to the dex writer. I fixed it by putting in the following in my app gradle.build: android { dexOptions { incremental true javaMaxHeapSize "4g" } } This option also managed to speed up my gradle build signifi...
Dex
32,553,245
21
Can any body please share the method to execute the dex file in android with command? This is just to understand.
Let's say you have a the following code in file HelloWorld.java: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } To run it on an android device: javac HelloWorld.java dx --dex --output=classes.dex HelloWorld.class zip HelloWorld.zip classes.de...
Dex
10,199,863
20