gpt4 book ai didi

android - 获取每个提供商和服务的所有加密算法

转载 作者:行者123 更新时间:2023-11-29 00:51:48 25 4
gpt4 key购买 nike

我叫 Panagiotis,我想与您分享我对我遇到的问题的解决方案。

我的问题:

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

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

帕纳约蒂斯万杰拉托斯

最佳答案

我在 Kotlin 中的解决方案:

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

private class AlgorithmsPerProviderAndService constructor(private val serviceName: String)
{
private val ServiceName: String get() = serviceName
val ProviderName: HashMap<String, ArrayList<String>> = 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()
}

希望能写出通俗易懂的评论!如果有人想讨论代码将是我的荣幸,我等待您的评论和优化!

万杰拉托斯·帕纳约蒂斯

关于android - 获取每个提供商和服务的所有加密算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58868132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com