Android:获取SSL证书作为流或字节[]

时间:2015-09-05 14:00:15

标签: java android ssl https

我需要在信任X509TrustManager之前手动检查ssl证书。如何在Android中下载ssl证书为字节或流?我知道如何将ssl证书作为java对象,但我需要bytes []或stream。

我注册了套接字工厂

schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

注册上下文

SSLContext context = SSLContext.getInstance("TLS");

和owerrided

public void checkServerTrusted(X509Certificate[] certificates, String authType)
            throws CertificateException 

对于ssl连接它工作正常,但我有一个证书作为java对象,但不是输入流或字节数组。

1 个答案:

答案 0 :(得分:0)

private SeekBar brightbar; //Variable to store brightness value private int brightness; //Content resolver used as a handle to the system's settings private ContentResolver Conresolver; //Window object, that will store a reference to the current window private Window window; /** Called when the activity is first created. */ @Override public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Instantiate seekbar object brightbar = (SeekBar) findViewById(R.id.ChangeBright); //Get the content resolver Conresolver = getContentResolver(); //Get the current window window = getWindow(); brightbar.setMax(255); brightbar.setKeyProgressIncrement(1); try { brightness = System.getInt(Conresolver, System.SCREEN_BRIGHTNESS); } catch (SettingNotFoundException e) { Log.e("Error", "Cannot access system brightness"); e.printStackTrace(); } brightbar.setProgress(brightness); brightbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) { System.putInt(Conresolver, System.SCREEN_BRIGHTNESS, brightness); LayoutParams layoutpars = window.getAttributes(); layoutpars.screenBrightness = brightness / (float) 255; window.setAttributes(layoutpars); } public void onStartTrackingTouch(SeekBar seekBar) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (progress <= 20) { brightness = 20; } else { brightness = progress; } } }); } 的成员X509Certificate应该返回getEncoded的编码形式的证书。

这对你有用吗?

http://docs.oracle.com/javase/7/docs/api/java/security/cert/Certificate.html#getEncoded()