Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取每个提供程序和服务的所有加密算法_Android_Security_Kotlin_Cryptography - Fatal编程技术网

Android 获取每个提供程序和服务的所有加密算法

Android 获取每个提供程序和服务的所有加密算法,android,security,kotlin,cryptography,Android,Security,Kotlin,Cryptography,我的名字是Panagiotis,我想和你们分享我对我面临的一个问题的解决方案 我的问题: 最近,我为我的应用程序创建了一个android库,实现了一些关于加密的标准功能。我的主要问题是我可以使用什么样的转换来加密和解密我的数据。我的第一步是在互联网上寻找信息,但我没有找到适合我的东西。我想要一个包含所有正确转换名称的列表 下面你会看到我的解决方案 Vangelatos Panagiotis我在Kotlin的解决方案: 首先,我创建了“AlgorithmsPerProviderAndService

我的名字是Panagiotis,我想和你们分享我对我面临的一个问题的解决方案

我的问题:

最近,我为我的应用程序创建了一个android库,实现了一些关于加密的标准功能。我的主要问题是我可以使用什么样的转换来加密和解密我的数据。我的第一步是在互联网上寻找信息,但我没有找到适合我的东西。我想要一个包含所有正确转换名称的列表

下面你会看到我的解决方案


Vangelatos Panagiotis

我在Kotlin的解决方案:

首先,我创建了“AlgorithmsPerProviderAndService”类,其中包含服务名称和每个提供者的所有可用算法

private class AlgorithmsPerProviderAndService constructor(private val serviceName: String)
{
    private val ServiceName:  String      get() = serviceName
    val ProviderName: HashMap<String, ArrayList<String>> = HashMap()
}
private class AlgorithmsPerProviderAndService构造函数(private val serviceName:String)
{
private val ServiceName:String get()=ServiceName
val ProviderName:HashMap=HashMap()
}
我创建了下面的代码部分,以获得android使用的每个服务和提供商的所有可用算法

    // StringBuilder object to display the data
    val sb  = StringBuilder()

    // "Info" HashMap that will has as key the name of the service and as value my custom class
    // that will hold the algorithm's names per provider
    val info: HashMap<String, AlgorithmsPerProviderAndService> = HashMap()

    // Part of code that reads all the available providers and for each provider get the 
    // corresponding services and the algorithm's names
    Security.getProviders().toList().sortedBy { it.name }.forEach {
        it.services.sortedBy { it1 -> it1.type }.forEach {it1 ->
            // Check if the "info" HashMap is empty and if is empty then add the first service
            // and the corresponding FIRST provider and FIRST algorithm
            if (info.size == 0)
            {
                val currentData = AlgorithmsPerProviderAndService(it1.type)
                currentData.ProviderName.put(it.name, arrayListOf(it1.algorithm))
                info.put(it1.type, currentData)
            }
            // If the "info" HashMap is not empty, then check if the current service already exists.
            // The reason that I check if the current services exists is because I want to have 
            // each service only one time into the "info" HashMap
            else
            {
                // Because the current service may have been implemented by more than one provider
                // and because I want to have the all algorithms that have been implemented by all 
                // provides, in case of the current service already exists, I check if the current
                // provider exists or not.
                if (info.containsKey(it1.type))
                {
                    // If the provider exists, I want to add only the available algorithms for the 
                    // current provider 
                    if (info[it1.type]!!.ProviderName.containsKey(it.name))
                    {
                        info[it1.type]!!.ProviderName[it.name]!!.add(it1.algorithm)
                    }
                    // If the provider does not exist, then I want to add both the new provider and 
                    // only the FIRST algorithm (because the other algorithms will be add when the 
                    // above condition is true)
                    else
                    {
                        info[it1.type]!!.ProviderName.put(it.name, arrayListOf(it1.algorithm))
                    }
                }
                // If this case, the current service does not exists, so adding it and in addition
                // I am adding provider (of the current service) and only the first algorithm.
                else
                {
                    val currentData = AlgorithmsPerProviderAndService(it1.type)
                    currentData.ProviderName.put(it.name, arrayListOf(it1.algorithm))
                    info.put(it1.type, currentData)
                }
            }
        }
    }

    // Display data
    info.toSortedMap().forEach {
        sb.appendln("Service: " + it.key)

        it.value.ProviderName.toSortedMap().forEach {it1 ->
            sb.appendln("\tProvider: " + it1.key)

            it1.value.sort()
            it1.value.forEach {it2 ->
                sb.appendln("\t\tAlgorithm: $it2")
            }

            sb.appendln()
        }

        sb.appendln()
    }
//用于显示数据的StringBuilder对象
val sb=StringBuilder()
//“Info”HashMap,它将服务的名称作为键,值作为我的自定义类
//这将保存每个提供程序的算法名称
val info:HashMap=HashMap()
//读取所有可用提供程序并为每个提供程序获取
//相应的服务和算法名称
Security.getProviders().toList().sortedBy{it.name}.forEach{
it.services.sortedBy{it1->it1.type}.forEach{it1->
//检查“info”HashMap是否为空,如果为空,则添加第一个服务
//以及对应的第一提供者和第一算法
如果(info.size==0)
{
val currentData=AlgorithmsPerProviderAndService(it1.type)
currentData.ProviderName.put(it.name,arrayListOf(it1.algorithm))
信息输入(it1.type,currentData)
}
//如果“info”HashMap不是空的,那么检查当前服务是否已经存在。
//我检查当前服务是否存在的原因是我希望
//每个服务仅一次进入“info”HashMap
其他的
{
//因为当前服务可能由多个提供商实现
//因为我想让所有人都能实现所有的算法
//提供,如果当前服务已经存在,我检查当前
//提供程序是否存在。
if(信息容器(it1.type))
{
//如果提供程序存在,我只想为
//当前提供者
if(info[it1.type]!!.ProviderName.containsKey(it.name))
{
info[it1.type]!!.ProviderName[it.name]!!.add(it1.algorithm)
}
//如果提供程序不存在,那么我想添加新的提供程序和
//只有第一个算法(因为当
//上述条件为真)
其他的
{
info[it1.type]!!.ProviderName.put(it.name,arrayListOf(it1.algorithm))
}
}
//如果是这种情况,则当前服务不存在,因此添加它并
//我正在添加(当前服务的)提供者,并且只添加第一个算法。
其他的
{
val currentData=AlgorithmsPerProviderAndService(it1.type)
currentData.ProviderName.put(it.name,arrayListOf(it1.algorithm))
信息输入(it1.type,currentData)
}
}
}
}
//显示数据
info.toSortedMap().forEach{
sb.appendln(“服务:+it.key”)
it.value.ProviderName.toSortedMap().forEach{it1->
sb.appendln(“\t提供程序:+it1.key”)
it1.value.sort()
it1.value.forEach{it2->
sb.appendln(“\t\tAlgorithm:$it2”)
}
(某人)
}
(某人)
}
我希望写下可以理解的评论!如果有人想讨论的代码将是我的愉快,我等待您的意见和优化

万吉拉托斯帕纳吉奥蒂斯