Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import java.util.Base64 to Android project? #2

Open
roblav96 opened this issue Dec 27, 2016 · 2 comments
Open

How to import java.util.Base64 to Android project? #2

roblav96 opened this issue Dec 27, 2016 · 2 comments

Comments

@roblav96
Copy link

roblav96 commented Dec 27, 2016

Currently my app crashes due to java.util.Base64 missing. I think it should be android.util.Base64?

https://github.com/fabiomsr/okhttp-peer-certificate-extractor/blob/master/src/main/java/org/fabiomsr/peercertificate/PeerCertificateExtractor.java#L11

@fabiomsr
Copy link
Owner

I think it should be android.util.Base64?

Yes.

You should remove these lines.

 byte[] publicKeyShaBase64 = Base64.getEncoder().encode(publicKeySha256);
return "sha256/" + new String(publicKeyShaBase64);

And add:

return "sha256/" + Base64.encodeToString(publicKeySha256, Base64.DEFAULT);

@roblav96
Copy link
Author

roblav96 commented Dec 29, 2016

@fabiomsr I found out that using okhttp3 you can call the method okhttp3.CertificatePinner.pin(x509Certificate) for example:

let inputStream: java.io.FileInputStream
try {
	let file = new java.io.File(options.certificateURI)
	inputStream = new java.io.FileInputStream(file)
	let x509Certificate = java.security.cert.CertificateFactory.getInstance('X509').generateCertificate(inputStream)
	peer.x509Certificate = x509Certificate
	certificate = okhttp3.CertificatePinner.pin(x509Certificate)
	inputStream.close()
} catch (error) {
	try {
		if (inputStream) {
			inputStream.close()
		}
	} catch (e) { }
	console.error('nativescript-https > enableSSLPinning error', error)
	return
}
// certificate = sha256/u4QJrwx7aSejc080BBQKGyTaoJovFBg4SbQ9nhoohb8=

Used in this library I wrote for Nativescript https://github.com/gethuman/nativescript-https/blob/master/https.android.ts#L41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants