Comments (5)
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.
@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.
@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.
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.
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)
- java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.widget.SearchView.setVisibility(int)' on a null object reference HOT 4
- OTP Page refreshed when came back from the SMS application HOT 3
- [2.4.6] The library doesn't compile HOT 13
- BENEFIT PAY HOT 1
- java.lang.ArrayIndexOutOfBoundsException: HOT 2
- Secret key not working its showing 401 invalid key error HOT 3
- Change the text color of the Cancel button HOT 2
- How to do Payment with already saved cards? in Android and iOS SDK. HOT 3
- Build failed HOT 1
- Card no saved once saved card switch is enable
- I have this error HOT 3
- 401 invalid api key HOT 3
- I have this issue please help
- in android 11 app is crashed HOT 5
- Payment view show automatic when page is load HOT 1
- Fatal Exception: java.lang.NullPointerException HOT 1
- NullPointerException inside CurrenciesActivity
- errorBody{"errors":[{"code":"2104","description":"Invalid API Key"}]} HOT 3
- App getting crash while proceed Payment HOT 1
- fatal: not a git repository (or any of the parent directories): .git
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gosellsdk-android.