Coder Social home page Coder Social logo

Comments (5)

GoltsevEugene avatar GoltsevEugene commented on July 24, 2024

Dear @milanPansuriya , seems like your encryption key is invalid.
Did you copy the encryption key from your dashboard?
Has the application crashed?

from gosellsdk-android.

milanPansuriya avatar milanPansuriya commented on July 24, 2024

@GoltsevEugene If I am using Gradle line than it crashes,
but if I am using as LIB project than it works
I think in Gradle Line project you missed IllegalArgumentException ex in CryptoUtil class line No.45

from gosellsdk-android.

GoltsevEugene avatar GoltsevEugene commented on July 24, 2024

@milanPansuriya, by Gradle Line you mean run project from console?
Actually, it doesn't crash, it prints stacktrace of exception - you can check line 43 in CryptoUtil class.

from gosellsdk-android.

milanPansuriya avatar milanPansuriya commented on July 24, 2024

This class from Gradle
`package company.tap.gosellapi.api.crypto;

import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.util.Base64;

import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

/**

  • Created by eugene.goltsev on 16.02.2018.

  • Util class for RSA encryption
    */

@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class CryptoUtil {
public static String encryptJsonString(@nonnull String jsonString, String encryptionKey) {
if(jsonString.length() == 0) {
throw new IllegalArgumentException("Parameter jsonString cannot be empty");
}

    return encrypt(jsonString, encryptionKey);
}

private static String encrypt(String encrypt, String encryptionKey) {
    String result = "";
    try {
        encryptionKey = encryptionKey.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "");

        byte[] publicBytes = Base64.decode(encryptionKey, Base64.DEFAULT);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey pubKey = keyFactory.generatePublic(keySpec);
        Cipher encryptCipher = Cipher.getInstance("RSA/None/PKCS1Padding");
        encryptCipher.init(Cipher.ENCRYPT_MODE, pubKey);
        result = Base64.encodeToString(encryptCipher.doFinal(encrypt.getBytes()), Base64.DEFAULT).replaceAll("\\n", "");
    } catch (GeneralSecurityException ex) {
        ex.printStackTrace();
    }
    return result;
}

}
`
And this class in Github

`package company.tap.gosellapi.api.crypto;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.util.Base64;

import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

/**

  • Created by eugene.goltsev on 16.02.2018.

  • Util class for RSA encryption
    */

@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class CryptoUtil {
public static String encryptJsonString(@nonnull String jsonString, String encryptionKey) {
if(jsonString.length() == 0) {
throw new IllegalArgumentException("Parameter jsonString cannot be empty");
}

    return encrypt(jsonString, encryptionKey);
}

private static String encrypt(String encrypt, String encryptionKey) {
    String result = "";
    try {
        encryptionKey = encryptionKey.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "");

        byte[] publicBytes = Base64.decode(encryptionKey, Base64.DEFAULT);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey pubKey = keyFactory.generatePublic(keySpec);
        Cipher encryptCipher = Cipher.getInstance("RSA/None/PKCS1Padding");
        encryptCipher.init(Cipher.ENCRYPT_MODE, pubKey);
        result = Base64.encodeToString(encryptCipher.doFinal(encrypt.getBytes()), Base64.DEFAULT).replaceAll("\\n", "");
    } catch (GeneralSecurityException|IllegalArgumentException ex) {
        ex.printStackTrace();
    }
    return result;
}

}`

from gosellsdk-android.

GoltsevEugene avatar GoltsevEugene commented on July 24, 2024

Thanks a lot, @milanPansuriya!
Really weird behaviour and I don't have explanations for that.
At the moment I released version 1.0.3, where two exception types are splitted in different clauses, so I'm closing this issue.

from gosellsdk-android.

Related Issues (20)

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.