GithubHelp home page GithubHelp logo

vpccmcrypt's People

Contributors

billp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mylittleswift

vpccmcrypt's Issues

Incomprehension

A lot of variables don't understand, for example:iv、adata

Java Cipher can't decrypt the encrypted text

I'm having a problem that a Java Cipher can't decrypt the encrypted text because the Tag is wrong. It fails with following error: mac check in CCM failed.

Her's a Java code I'm using:

import java.math.BigInteger;
import java.security.*;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.modes.CCMBlockCipher;
import org.bouncycastle.crypto.params.CCMParameters;
import org.bouncycastle.crypto.params.KeyParameter;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class ADYDecrypt
{
  private static String AES = "AES";

  public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

  public static void main(String[] args)
  {

    try {

      byte[] encrypted = hexStringToByteArray(args[0]);
      byte[] keybytes = hexStringToByteArray("366D2C7804AEC975A7AB66BCF7B4A3DFA86476CCC5EFC7062CD2E80471FD663E");
      SecretKey key = new SecretKeySpec(keybytes, AES);
      byte[] iv = hexStringToByteArray("547971D2272DFA601147C8C1");
      byte[] plain;

      Security.addProvider(new BouncyCastleProvider());
      Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding");
      cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
      plain = cipher.doFinal(encrypted);


      System.out.println(args[0] + " -> " + new String(plain));
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

  }
}

The plain text I'm encryption is abc123456, the key is 366D2C7804AEC975A7AB66BCF7B4A3DFA86476CCC5EFC7062CD2E80471FD663E, the iv is 547971D2272DFA601147C8C1 and the tag length is 8.

The encryption with your library gives 8aadc9c57ce679dc99 c37bc73cf9bb5fa8 (secod one is the tag).
While the encryption with OpenSSL (EVP_CIPHER_CTX) is 8AADC9C57CE679DC99 B4FB1B4CD037A4BE

So it seems the Tag calculation is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.