最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java的java.security.egd源碼解讀

 更新時間:2023年08月22日 09:38:45   作者:codecraft  
這篇文章主要為大家介紹了java的java.security.egd源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下java的java.security.egd

SunEntries

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/SunEntries.java

// name of the *System* property, takes precedence over PROP_RNDSOURCE
    private final static String PROP_EGD = "java.security.egd";
    // name of the *Security* property
    private final static String PROP_RNDSOURCE = "securerandom.source";
    final static String URL_DEV_RANDOM = "file:/dev/random";
    final static String URL_DEV_URANDOM = "file:/dev/urandom";
    private static final String seedSource;
    static {
        seedSource = AccessController.doPrivileged(
                new PrivilegedAction<String>() {
            @Override
            public String run() {
                String egdSource = System.getProperty(PROP_EGD, "");
                if (egdSource.length() != 0) {
                    return egdSource;
                }
                egdSource = Security.getProperty(PROP_RNDSOURCE);
                if (egdSource == null) {
                    return "";
                }
                return egdSource;
            }
        });
    }

 這里優(yōu)先讀取java.security.egd,如果沒有設(shè)置則讀取$JAVA_HOME/jre/lib/security/java.security文件中的securerandom.source配置,默認(rèn)值為file:/dev/random

SeedGenerator

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/SeedGenerator.java

// Static initializer to hook in selected or best performing generator
    static {
        String egdSource = SunEntries.getSeedSource();
        /*
         * Try the URL specifying the source (e.g. file:/dev/random)
         *
         * The URLs "file:/dev/random" or "file:/dev/urandom" are used to
         * indicate the SeedGenerator should use OS support, if available.
         *
         * On Windows, this causes the MS CryptoAPI seeder to be used.
         *
         * On Solaris/Linux/MacOS, this is identical to using
         * URLSeedGenerator to read from /dev/[u]random
         */
        if (egdSource.equals(SunEntries.URL_DEV_RANDOM) ||
                egdSource.equals(SunEntries.URL_DEV_URANDOM)) {
            try {
                instance = new NativeSeedGenerator(egdSource);
                if (debug != null) {
                    debug.println(
                        "Using operating system seed generator" + egdSource);
                }
            } catch (IOException e) {
                if (debug != null) {
                    debug.println("Failed to use operating system seed "
                                  + "generator: " + e.toString());
                }
            }
        } else if (egdSource.length() != 0) {
            try {
                instance = new URLSeedGenerator(egdSource);
                if (debug != null) {
                    debug.println("Using URL seed generator reading from "
                                  + egdSource);
                }
            } catch (IOException e) {
                if (debug != null) {
                    debug.println("Failed to create seed generator with "
                                  + egdSource + ": " + e.toString());
                }
            }
        }
        // Fall back to ThreadedSeedGenerator
        if (instance == null) {
            if (debug != null) {
                debug.println("Using default threaded seed generator");
            }
            instance = new ThreadedSeedGenerator();
        }
    }

 如果是file:/dev/randomfile:/dev/urandom則走NativeSeedGenerator,不是則走URLSeedGenerator,為空則走ThreadedSeedGenerator

NativeSeedGenerator

/**
 * Native seed generator for Unix systems. Inherit everything from
 * URLSeedGenerator.
 *
 */
class NativeSeedGenerator extends SeedGenerator.URLSeedGenerator {
    NativeSeedGenerator(String seedFile) throws IOException {
        super(seedFile);
    }
}
NativeSeedGenerator繼承了URLSeedGenerator

SecureRandomSpi

NativePRNG

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/NativePRNG.java

public final class NativePRNG extends SecureRandomSpi {
    private static final long serialVersionUID = -6599091113397072932L;
    private static final Debug debug = Debug.getInstance("provider");
    // name of the pure random file (also used for setSeed())
    private static final String NAME_RANDOM = "/dev/random";
    // name of the pseudo random file
    private static final String NAME_URANDOM = "/dev/urandom";
    // which kind of RandomIO object are we creating?
    private enum Variant {
        MIXED, BLOCKING, NONBLOCKING
    }
    // singleton instance or null if not available
    private static final RandomIO INSTANCE = initIO(Variant.MIXED);
    /**
     * Get the System egd source (if defined).  We only allow "file:"
     * URLs for now. If there is a egd value, parse it.
     *
     * @return the URL or null if not available.
     */
    private static URL getEgdUrl() {
        // This will return "" if nothing was set.
        String egdSource = SunEntries.getSeedSource();
        URL egdUrl;
        if (egdSource.length() != 0) {
            if (debug != null) {
                debug.println("NativePRNG egdUrl: " + egdSource);
            }
            try {
                egdUrl = new URL(egdSource);
                if (!egdUrl.getProtocol().equalsIgnoreCase("file")) {
                    return null;
                }
            } catch (MalformedURLException e) {
                return null;
            }
        } else {
            egdUrl = null;
        }
        return egdUrl;
    }
    //......
}

 NativePRNG的getEgdUrl則通過egdSource來構(gòu)建URL

小結(jié)

  • SunEntries優(yōu)先讀取java.security.egd,如果沒有設(shè)置則讀取$JAVA_HOME/jre/lib/security/java.security文件中的securerandom.source配置,默認(rèn)值為file:/dev/random
  • SeedGenerator判斷egdSource如果是file:/dev/randomfile:/dev/urandom則走NativeSeedGenerator,不是則走URLSeedGenerator,為空則走ThreadedSeedGenerator
  • 至于/dev/./urandom這種表示看起來比較困惑,翻譯過來就是是/dev當(dāng)前目錄下的unrandom,其實就是/dev/urandom,之所以有這種傳參主要是早期jdk版本有個bug,沒有給NativeSeedGenerator傳參,所以通過file:/dev/./urandom繞過這個bug

doc

以上就是java的java.security.egd的詳細(xì)內(nèi)容,更多關(guān)于java.security.egd的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • SpringBoot處理全局統(tǒng)一異常的實現(xiàn)

    SpringBoot處理全局統(tǒng)一異常的實現(xiàn)

    這篇文章主要介紹了SpringBoot處理全局統(tǒng)一異常的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • springboot整合quartz定時任務(wù)框架的完整步驟

    springboot整合quartz定時任務(wù)框架的完整步驟

    在做項目時有時候會有定時器任務(wù)的功能,比如某某時間應(yīng)該做什么,多少秒應(yīng)該怎么樣之類的,下面這篇文章主要給大家介紹了關(guān)于springboot整合quartz定時任務(wù)框架的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • java后臺判斷客戶端是手機(jī)/PC并返回不同頁面的實例

    java后臺判斷客戶端是手機(jī)/PC并返回不同頁面的實例

    下面小編就為大家分享一篇java后臺判斷客戶端是手機(jī)/PC并返回不同頁面的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Java停止線程的3種方法

    Java停止線程的3種方法

    這篇文章主要分享Java停止線程的3種方法,分別是自定義中斷標(biāo)識符,停止線程、使用線程中斷方法interrupt停止線程、使用stop停止線程。下文詳細(xì)介紹需要的小伙伴可以參考一下
    2022-05-05
  • java中棧和隊列的實現(xiàn)和API的用法(詳解)

    java中棧和隊列的實現(xiàn)和API的用法(詳解)

    下面小編就為大家?guī)硪黄猨ava中棧和隊列的實現(xiàn)和API的用法(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • Java中的緩沖區(qū)(Buffer)及其作用是什么詳解

    Java中的緩沖區(qū)(Buffer)及其作用是什么詳解

    緩沖區(qū)用于提升I/O效率,Java提供字符流、字節(jié)流及ByteBuffer類型,擁有capacity、position等屬性,這篇文章主要介紹了Java中的緩沖區(qū)(Buffer)及其作用是什么的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-05-05
  • Java十分鐘精通集合的使用與原理下篇

    Java十分鐘精通集合的使用與原理下篇

    這章就對上一章的集合進(jìn)行代碼操作,去學(xué)習(xí)如果創(chuàng)建集合,以及對集合數(shù)據(jù)的處理,下面跟小編一起來看看吧
    2022-03-03
  • SpringCloud Gateway自定義filter獲取body中的數(shù)據(jù)為空的問題

    SpringCloud Gateway自定義filter獲取body中的數(shù)據(jù)為空的問題

    這篇文章主要介紹了SpringCloud Gateway自定義filter獲取body中的數(shù)據(jù)為空,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • Java中的cglib原理解析

    Java中的cglib原理解析

    這篇文章主要介紹了Java中的cglib原理解析,由于代理類繼承了被代理類,所以調(diào)用sayHello()方法時會直接調(diào)用代理類的sayHello()方法,而在代理類的方法中,調(diào)用了Callback的邏輯,需要的朋友可以參考下
    2023-10-10
  • Spring?Data?JPA框架快速入門之自定義Repository接口

    Spring?Data?JPA框架快速入門之自定義Repository接口

    Spring?Data?JPA是Spring基于JPA規(guī)范的基礎(chǔ)上封裝的?套?JPA?應(yīng)?框架,可使開發(fā)者?極簡的代碼即可實現(xiàn)對數(shù)據(jù)庫的訪問和操作,本篇我們來了解Spring?Data?JPA框架的自定義Repository接口
    2022-04-04

最新評論

宁武县| 渭源县| 金华市| 岑巩县| 区。| 什邡市| 晋城| 青神县| 广安市| 阳朔县| 根河市| 久治县| 淳化县| 阳朔县| 鸡西市| 长子县| 眉山市| 偏关县| 苏尼特右旗| 乌苏市| 建德市| 乌什县| 富川| 双柏县| 枣强县| 宝兴县| 崇文区| 荆州市| 东辽县| 定日县| 宁晋县| 蓝山县| 桑植县| 巴里| 溆浦县| 马山县| 安乡县| 衡阳市| 辽中县| 五指山市| 平昌县|