首页 > 作文

Java KeyGenerator.generateKey的19个方法代码示例

更新时间:2023-04-04 07:14:51 阅读: 评论:0

目录
示例1: encryptbyaes示例2: main示例3: wrapperpublicprivitekeytest示例4: inithmacsha224key示例5: run示例6: inithmacsha384key示例7: wrapperblowfishkeytest示例8: generatemacsha1key示例9: readwriteskip示例10: generatekey示例11: generateencryptioncret​ 示例12: inithmacsha512key示例13: initkey示例14: inithmacshakey示例15: inithmacmd4key示例16: inithmacmd5key示例17: runtest示例18: runtest示例19: s_genkeys

本文整理汇总了java中javax.crypto.keygenerator.generatekey方法的典型用法代码示例。如果您正苦于以下问题:java keygenerator.generatekey方法的具体用法?java keygenerator.generatekey怎么用?java keygenerator.generatekey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.crypto.keygenerator的用法示例。

在下文中一共展示了keygenerator.generatekey方法的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的java代码示例。

示例1: encryptbyaes

import javax.crypto.keygenerator; //导入方法依赖的package包/类public encryptbyaes() {        try {            //生成key            keygenerator keygenerator = keygenerator.getinstance("aes");            keygenerator.init(256);            //产生秘钥            cretkey cretkey = keygenerator.generatekey();            //获取秘钥            byte[] keybytes = cretkey.getencoded();            // logger.e("aes key=" + ba64.encodetostring(keybytes, ba64.url_safe));            //还原秘钥            key = new cretkeyspec(keybytes, "aes");        } catch (nosuchalgorithmexception e) {            e.printstacktrace();        }    }

开发者id:zhonglikui,项目名称:cardinalssample,代码行数:20,代码来源:encryptbyaes.java

示例2: main

import javax.crypto.keygenerator; //导入方法依赖的package包/类public static void main(string[] args) throws exception {    provider provider = curity.getprovider("sunjce");    keygenerator kg;    kg = keygenerator.getinstance("suntlsrsapremastercret", provider);    try {        kg.generatekey();        throw new exception("no exception");    } catch (illegalstateexception e) {        system.out.println("ok: " + e);    }    int[] protocolversions = {0x0300, 0x0301, 0x0302, 0x0400};    for (int clientversion : protocolversions) {        for (int rverversion : protocolversions) {            test(kg, clientversion, rverversion);            if (rverversion >= clientversion) {                break;            }        }    }    syst认时间em.out.println("done.");}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:testpremaster.java

示例3: wrapperpublicprivitekeytest

import javax.crypto.keygenerator; //导入方法依赖的package包/类private void wrapperpublicprivitekeytest(provider p, string[] algorithms)        throws nosuchalgorithmexception, invalidkeyexception,        nosuchpaddingexception, illegalblocksizeexception,        invalidalgorithmparameterexception {    for (string algo : algorithms) {        // key pair generated        system.out.println("generate key pair (algorithm: " + algo                + ", provider: " + p.getname() + ")");        keypairgenerator kpg = keypairgenerator.getinstance(algo);        kpg.initialize(512);        keypair kp = kpg.genkeypair();        // key generated        string algowrap = "des";        keygenerator kg = keygenerator.getinstance(algowrap, p);        key key = kg.generatekey();        wraptest(algo, algowrap, key, kp.getprivate(), cipher.private_key,                fal);        wraptest(algo, algowrap, key, kp.getpublic(), cipher.public_key,                fal);    }}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:testcipherkeywrappertest.java

示例4: inithmacsha224key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 初始化hmacsha224密钥 *  * @return byte[] 密钥 * @throws exception */public static byte[] inithmacsha224key() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmacsha224");    // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:guokezheng,项目名称:automat,代码行数:15,代码来源:hmaccoder.java

示例5: run

import javax.crypto.keygenerator; //导入方法依赖的package包/类private void run(string keystoretype) throws exception {    char[] pw = "password".tochararray();    keystore ks = keystore.getinstance(keystoretype);    ks.load(null, pw);    keygenerator kg = keygenerator.getinstance("aes");    kg.init(128);    cretkey key = kg.generatekey();    keystore.cretkeyentry ske = new keystore.cretkeyentry(key);    keystore.protectionparameter kspp = new keystore.passwordprotection(pw);    ks.tentry(alias, ske, kspp);    file ksfile = file.createtempfile("test", ".test");    try (fileoutputstream fos = new fileoutputstream(ksfile)) {        ks.store(fos, pw);        fos.flush();    }    // now e if we can get it back    try (fileinputstream fis = new fileinputstream(ksfile)) {        keystore ks2 = keystore.getinstance(keystoretype);        ks2.load(fis, pw);        keystore.entry entry = ks2.getentry(alias, kspp);        cretkey keyin = ((keystore.cretkeyentry)entry).getcretkey();        if (arrays.equals(key.getencoded(), keyin.getencoded())) {            system.err.println("ok: worked just fine with " + keystoretype +                               " keystore");        } el {            system.err.println("error: keys are not equal after storing in "                               + keystoretype + " keystore");        }    }}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:p12cretkey.java

示例6: inithmacsha384key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 初始化hmacsha384密钥 *  * @return * @throws exception */public static byte[] inithmacsha384key() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmacsha384");   运城大学 // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:babymm,项目名称:mumu,代码行数:15,代码来源:hmaccoder.java

示例7: wrapperblowfishkeytest

import javax.crypto.keygenerator; //导入方法依赖的package包/类private void wrapperblowfishkeytest() throws invalidkeyexception,        nosuchalgorithmexception, nosuchpaddingexception,        illegalblocksizeexception, invalidalgorithmparameterexception {    // how many kinds of padding mode    int padkinds;    // keysize should be multiple of 8 bytes.    int keycutter = 8;    int ksize = blowfish_min_keysize;    string algorithm = "blowfish";    int maxallowkeylength = cipher.getmaxallowedkeylength(algorithm);    boolean unlimitpolicy = maxallowkeylength == integer.max_value;    cretkey key = null;    while (ksize <= blowfish_max_keysize) {        for (string mode : model_ar) {            // pkcs5padding is meaningful only for ecb, cbc, pcbc            if (mode.equalsignoreca(model_ar[0])                    || mode.equalsignoreca(model_ar[1])                    || mode.equalsignoreca(model_ar[2])) {                padkinds = padding_ar.length;            } el {                padkinds = 1;            }            // initialization            keygenerator kg = keygenerator.getinstance(algorithm);            for (int k = 0; k < padkinds; k++) {                string transformation = algorithm + "/" + mode + "/"                        + padding_ar[k];                if (nopadding.equals(padding_ar[k]) && ksize % 64 != 0) {                    out.println(transformation                     泡沫邓紫棋       + " will not run if input length not multiple"                            + " of 8 bytes when padding is " + nopadding);                    continue;                }                kg.init(ksize);                key = kg.generatekey();                // only run the tests on longer key lengths if unlimited                // version of jce jurisdiction policy files are installed                if (!unlimitpolicy && ksize > linimited_keysize) {                    out.println("keystrength > 128 within " + algorithm                            + " will not run under global policy");                } el {                    wraptest(transformation, transformation, key, key,                            cipher.cret_key, fal);                }            }        }        if (ksize <= linimited_keysize) {            keycutter = 8;        } el {            keycutter = 48;        }        ksize += keycutter;    }}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:55,代码来源:testcipherkeywrappertest.java

示例8: generatemacsha1key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 生成hmac-sha1密钥,返回字节数组,长度为160位(20字节). * hmac-sha1算法对密钥无特殊要求, rfc2401建议最少长度为160位(20字节). */public static byte[] generatemacsha1key() {    try {        keygenerator keygenerator = keygenerator.getinstance(hmacsha1);        keygenerator.init(default_hmacsha1_keysize);        cretkey cretkey = keygenerator.generatekey();        return cretkey.getencoded();    } catch (generalcurityexception e) {        throw exceptionutils.unchecked(e);    }}

开发者id:wkeyuan,项目名称:dwsurvey,代码行数:15,代码来源:cryptoutils.java

示例9: readwriteskip

import javax.crypto.keygenerator; //导入方法依赖的package包/类readwriteskip(int keylength, int textlength, int aadlength)        throws exception {    this.keylength = keylength;    this.textlength = textlength;    // init aad    this.aad = helper.generatebytes(aadlength);    // init a cret key    keygenerator kg = keygenerator.getinstance(aes, provider);    kg.init(this.keylength);    this.key = kg.generatekey();    this.plaintext = helper.generatebytes(textlength);}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:readwriteskip.java

示例10: generatekey

import javax.crypto.keygenerator; //导入方法依赖的package包/类public static byte[] generatekey( byte[] ed ) throws exception{    keygenerator keygenerator = keygenerator.getinstance( cipher_algorithm );    curerandom curerandom = curerandom.getinstance( random_generator_algorithm );    curerandom.ted( ed );    keygenerator.init( random_key_size, curerandom );    cretkey cretkey = keygenerator.generatekey();    return cretkey.getencoded();}

开发者id:sdrausty,项目名称:buildapkssamples,代码行数:10,代码来源:stringcryptor.java

示例11: generateencryptioncret​

import javax.crypto.keygenerator; //导入方法依赖的package包/类private static byte[] generateencryptioncret() {  try {    keygenerator generator = keygenerator.getinstance("aes");    generator.init(128);    cretkey key = generator.generatekey();    return key.getencoded();  } catch (nosuchalgorithmexception ex) {    log.w("keyutil", ex);    return null;  }}

开发者id:cableim,项目名称:cable-android,代码行数:13,代码来源:mastercretutil.java

示例12: inithmacsha512key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 初始化hmacsha512密钥 *  * @return * @throws exception */public static byte[] inithmacsha512key() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmacsha512");    // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:mumucommon,项目名称:mumu-core,代码行数:15,代码来源:hmaccoder.java

示例13: initkey

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 生成密钥 * * @param keysize * @return */public byte[] initkey(int keysize) {    keygenerator keygen = null;    try {        keygen = keygenerator.getinstance("aes");        keygen.init(keysize);  //192 256    } catch (nosuchalgorithmexception e) {        e.printstacktrace();    }    cretkey cretkey = keygen.generatekey();    return cretkey.getencoded();}

开发者id:jopenbox,项目名称:android-lite-utils,代码行数:18,代码来源:aesutils.java

示例14: inithmacshakey

import javax.crypto.keygenerator计算机大学; //导入方法依赖的package包/类/** * 初始化hmacsha1密钥 *  * @return * @throws exception */public static byte[] inithmacshakey() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmactiger");    // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:guokezheng,项目名称:automat,代码行数:15,代码来源:hmaccoder.java

示例15: inithmacmd4key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 初始化hmacmd4密钥 *  * @return byte[] 密钥 * @throws exception */public static byte[] inithmacmd4key() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmacmd4");    // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:iba4j,项目名称:iba4j-common,代码行数:15,代码来源:hmaccoder.java

示例16: inithmacmd5key

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 初始化hmacmd5密钥 *  * @return * @throws exception */public static byte[] inithmacmd5key() throws exception {    // 初始化keygenerator    keygenerator keygenerator = keygenerator.getinstance("hmacmd5");    // 产生秘密密钥    cretkey cretkey = keygenerator.generatekey();    // 获得密钥    return cretkey.getencoded();}

开发者id:iba4j,项目名称:iba4j-common,代码行数:15,代码来源:hmaccoder.java

示例17: runtest

import javax.crypto.keygenerator; //导入方法依赖的package包/类private static void runtest(provider p, string algo, string mo, string pad,        readmodel whichread) throws generalcurityexception, ioexception {    // do initialization    byte[] plaintext = testutilities.generatebytes(text_length);    byte[] iv = testutilities.generatebytes(iv_length);    algorithmparameterspec aps = new ivparameterspec(iv);    try {        keygenerator kg = keygenerator.getinstance(algo, p);        out.println(algo + "/" + mo + "/" + pad + "/" + whichread);        cretkey key = kg.generatekey();        cipher ci1 = cipher.getinstance(algo + "/" + mo + "/" + pad, p);        if ("cfb72".equalsignoreca(mo) || "ofb20".equalsignoreca(mo)) {            throw new runtimeexception(                    "nosuchalgorithmexception not throw when mode"                            + " is cfb72 or ofb20");        }        cipher ci2 = cipher.getinstance(algo + "/" + mo + "/" + pad, p);        if ("ecb".equalsignoreca(mo)) {            ci1.init(cipher.encrypt_mode, key);            ci2.init(cipher.decrypt_mode, key);        } el {            ci1.init(cipher.encrypt_mode, key, aps);            ci2.init(cipher.decrypt_mode, key, aps);        }        bytearrayoutputstream baoutput = new bytearrayoutputstream();        try (cipherinputstream cinput                = new cipherinputstream(                        new bytearrayinputstream(plaintext), ci1);                cipheroutputstream cioutput                    = new cipheroutputstream(baoutput, ci2);) {            // read from the input and write to the output using 2 types            // of buffering : byte[] and int            whichread.read(cinput, cioutput, ci1, plaintext.length);        }        // verify input and output are same.        if (!arrays.equals(plaintext, baoutput.tobytearray())) {            throw new runtimeexception("test failed due to compare fail ");        }    } catch (nosuchalgorithmexception nsaex) {        if ("cfb72".equalsignoreca(mo) || "ofb20".equalsignoreca(mo)) {            out.println("nosuchalgorithmexception is expected for cfb72 and ofb20");        } el {            throw new runtimeexception("unexpected exception testing: "                    + algo + "/" + mo + "/" + pad + "/" + whichread, nsaex);        }    }}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:cicodesfunctest.java

示例18: runtest

import javax.crypto.keygenerator; //导入方法依赖的package包/类private static void runtest(datatuple datatuple)        throws nosuchalgorithmexception, nosuchproviderexception,        invalidkeyexception {    mac mcalgorithm = mac.getinstance(datatuple.algorithm,            provider_name);    mac mcoid = mac.getinstance(datatuple.oid, provider_name);    if (mcalgorithm == null) {        throw new runtimeexception(string.format(                "test failed: mac using algorithm "                        + "string %s getinstance failed.%n",                datatuple.algorithm));    }    if (mcoid == null) {        throw new runtimeexception(string.format(                "test failed: mac using oid %s getinstance failed.%n",                datatuple.oid));    }    if (!mcalgorithm.getalgorithm().equals(datatuple.algorithm)) {        throw new runtimeexception(string.format(                "test failed: mac using algorithm string %s getinstance "                        + "doesn't generate expected algorithm.%n",                datatuple.algorithm));    }    keygenerator kg = keygenerator.getinstance(datatuple.algorithm,            provider_name);    cretkey key = kg.generatekey(); 陶渊明   mcalgorithm.init(key);    mcalgorithm.update(input);    mcoid.init(key);    mcoid.update(input);    // comparison    if (!arrays.equals(mcalgorithm.dofinal(), mcoid.dofinal())) {        throw new runtimeexception("digest comparison failed: "                + "the two macs are not the same");    }}

开发者id:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:44,代码来源:testhmacshaoids.java

示例19: s_genkeys

import javax.crypto.keygenerator; //导入方法依赖的package包/类/** * 通过种子生成二进制密钥 *  * @param _arg *            生成私钥的种子 * @return * @throws exception */public static byte[] s_genkeys( string _arg ) throws exception {    keygenerator key_generator = keygenerator.getinstance( algorithm );    curerandom cure_random = new curerandom( ba64.decode( _arg.getbytes() ) );    key_generator.init( cure_random );    cretkey cret_key = key_generator.generatekey();    return cret_key.getencoded();}

开发者id:aiyoyoyo,项目名称:jeesupport,代码行数:16,代码来源:desutils.java

注:本文中的javax.crypto.keygenerator.generatekey方法示例整理自github/msdocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的licen;未经允许,请勿转载。

本文发布于:2023-04-04 07:14:49,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/129fceedb24dece7920c799be103aeb8.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Java KeyGenerator.generateKey的19个方法代码示例.doc

本文 PDF 下载地址:Java KeyGenerator.generateKey的19个方法代码示例.pdf

标签:示例   代码   密钥   开发者
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图