简体   繁体   English

加密Android

[英]Encryption Android

I'm trying to understand a code that lists all supported encryption algorithms on an Android device. 我正在尝试理解一个列出Android设备上所有受支持的加密算法的代码。 I'm just wondering why is it necessary to add the step with ('Alg.Alias') and remove these characters from the service name ? 我只是想知道为什么有必要添加('Alg.Alias')步骤并从服务名称中删除这些字符? The application stops working without it and I don't understand why ! 没有它,该应用程序将停止工作,我不明白为什么!

package com.example.lab_enc_dec; 包com.example.lab_enc_dec;

import java.security.Provider;
import java.security.Security;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import com.example.lab_enc_dec.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ListCryptoAlgorithms extends Activity {
    static final String TAG = "ListCryptoAlgorithms";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.algorithm_list);

        ListSupportedAlgorithms();
    }

    public void ListSupportedAlgorithms() {
        String result = "";

        // get all the providers
        Provider[] providers = Security.getProviders();

        for (int p = 0; p < providers.length; p++) {
            // get all service types for a specific provider
            Set<Object> ks = providers[p].keySet();
            Set<String> servicetypes = new TreeSet<String>();
            for (Iterator<Object> it = ks.iterator(); it.hasNext();) {
                String k = it.next().toString();
                k = k.split(" ")[0];
                if (k.startsWith("Alg.Alias."))
                    k = k.substring(10);                

                servicetypes.add(k.substring(0, k.indexOf('.')));
            }

            // get all algorithms for a specific service type
            int s = 1;
            for (Iterator<String> its = servicetypes.iterator(); its.hasNext();) {
                String stype = its.next();
                Set<String> algorithms = new TreeSet<String>();
                for (Iterator<Object> it = ks.iterator(); it.hasNext();) {
                    String k = it.next().toString();
                    k = k.split(" ")[0];
                    if (k.startsWith(stype + "."))
                        algorithms.add(k.substring(stype.length() + 1));
                    else if (k.startsWith("Alg.Alias." + stype +".")) 
                        algorithms.add(k.substring(stype.length() + 11));
                }

                int a = 1;
                for (Iterator<String> ita = algorithms.iterator(); ita.hasNext();) {
                    result += ("[P#" + (p + 1) + ":" + providers[p].getName() + "]" +
                            "[S#" + s + ":" + stype + "]" +
                            "[A#" + a + ":" + ita.next() + "]\n");
                    a++;
                }

                s++;
            }
        }

        TextView tv = (TextView)findViewById(R.id.supp_alg_result);
        tv.setText(result);
    }

}

Aliases are aliases to existing algorithms that have been registered under a different name. 别名是使用其他名称注册的现有算法的别名。 Those names are prefixed with "Alg.Alias." 这些名称以"Alg.Alias."为前缀"Alg.Alias." in the list so they can be distinguished from the initial registration. 在列表中,因此可以将它们与初始注册区分开。 However, you should not use "Alg.Alias" in the getInstance methods of the various JCE classes such as Cihper . 但是,不应在各种JCE类(例如CihpergetInstance方法中使用"Alg.Alias" Hence the list removes the "Alg.Alias." 因此,该列表删除了"Alg.Alias." from the service name. 从服务名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM