在Java中如何工作

在Java中如何工作

本文介绍了SecureRandom.getInstance()在Java中如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这里我正在使用 SecureRandom random = SecureRandom.getInstance(here my name); 但是在我们的项目中没有任何异常。但是当我运行main方法时,它会给 NoSuchAlgorithm Exception 我的异常,对我来说这是正常的。这是什么原因。我有混乱吗? 但是在这里我得到异常为什么?请帮助我。提前谢谢... 解决方案事实上,你可以将一个字符串传递给 SecureRandom.getInstance 并获得一个有效的结果不能保证将相同的字符串传递给 KeyGenerator.getInstance 也将成功。 要查找系统支持哪些算法,运行此代码,并查看结果: $ b $ (Provider p:Security.getProviders()){ for(Object o:p.keySet()){系统.out.println(O); } } 输出将包含如下所示的行: / p> Cipher.AES KeyGenerator.RC2 Mac.HmacSHA512 ... SecureRandom.NativePRNG SecureRandom.SHA1PRNG ... KeyGenerator.DES KeyGenerator.DESede 前缀为SecureRandom的名称(即NativePRNG ,SHA1PRNG)可以传递给 SecureRandom.getInstance ,而前缀为KeyGenerator的名称。 (即RC2,DES,DESede)可以传递给 KeyGenerator.getInstance 。 Here i am usingSecureRandom random = SecureRandom.getInstance("here my name") ;But it is not giving any exception in our project.But when i run using main method it is giving NoSuchAlgorithm Exception exception for me.Also it is working fine for me.What it the reason.I am in confusion?KeyGenerator keyGen = KeyGenerator.getInstance("here my name");But here i am getting exception why?Please help me .Thanks in advance... 解决方案 The fact that you can pass a string to SecureRandom.getInstance and get a valid result does not guarantee that passing the same string to KeyGenerator.getInstance would also be successful.To find out what algorithms are supported on your system, run this code, and look at the results:for (Provider p : Security.getProviders()) { for (Object o : p.keySet()) { System.out.println(o); }}The output will contain lines that look like this:Cipher.AESKeyGenerator.RC2Mac.HmacSHA512...SecureRandom.NativePRNGSecureRandom.SHA1PRNG...KeyGenerator.DESKeyGenerator.DESedeThe names prefixed with "SecureRandom." (i.e. "NativePRNG", '"SHA1PRNG"') can be passed to SecureRandom.getInstance, while the names prefixed with "KeyGenerator." (i.e. "RC2", "DES", "DESede") can be passed to KeyGenerator.getInstance. 这篇关于SecureRandom.getInstance()在Java中如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 14:41