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

目录
  • 示例1: EncryptByAes
  • 示例2: main
  • 示例3: wrapperPublicPriviteKeyTest
  • 示例4: initHmacSHA224Key
  • 示例5: run
  • 示例6: initHmacSHA384Key
  • 示例7: wrapperBlowfishKeyTest
  • 示例8: generateMacSha1Key
  • 示例9: ReadWriteSkip
  • 示例10: generateKey
  • 示例11: generateEncryptionSecret​
  • 示例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);
            //产生秘钥
            SecretKey secretKey = keyGenerator.generateKey();
            //获取秘钥
            byte[] keyBytes = secretKey.getEncoded();
            // Logger.e("AES Key=" + Base64.encodeToString(keyBytes, Base64.URL_SAFE));
            //还原秘钥
            key = new SecretKeySpec(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 = Security.getProvider("SunJCE");

    KeyGenerator kg;

    kg = KeyGenerator.getInstance("SunTlsRsaPremasterSecret", 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 serverVersion : protocolVersions) {
            test(kg, clientVersion, serverVersion);
            if (serverVersion >= clientVersion) {
                break;
            }
        }
    }

    System.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,
                false);
        wrapTest(algo, algoWrap, key, kp.getPublic(), Cipher.PUBLIC_KEY,
                false);
    }
}

开发者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");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.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);
    SecretKey key = kg.generateKey();

    KeyStore.SecretKeyEntry ske = new KeyStore.SecretKeyEntry(key);
    KeyStore.ProtectionParameter kspp = new KeyStore.PasswordProtection(pw);
    ks.setEntry(ALIAS, ske, kspp);

    File ksFile = File.createTempFile("test", ".test");
    try (FileOutputStream fos = new FileOutputStream(ksFile)) {
        ks.store(fos, pw);
        fos.flush();
    }

    // now see 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);
        SecretKey keyIn = ((KeyStore.SecretKeyEntry)entry).getSecretKey();
        if (Arrays.equals(key.getEncoded(), keyIn.getEncoded())) {
            System.err.println("OK: worked just fine with " + keystoreType +
                               " keystore");
        } else {
            System.err.println("ERROR: keys are NOT equal after storing in "
                               + keystoreType + " keystore");
        }
    }
}

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

示例6: initHmacSHA384Key

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 初始化HmacSHA384密钥
 *
 * @return
 * @throws Exception
 */
public static byte[] initHmacSHA384Key() throws Exception {
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacSHA384");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.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;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                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");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            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);
        SecretKey secretKey = keyGenerator.generateKey();
        return secretKey.getEncoded();
    } catch (GeneralSecurityException 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 secret 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[] seed ) throws Exception
{
    KeyGenerator keyGenerator = KeyGenerator.getInstance( CIPHER_ALGORITHM );
    SecureRandom secureRandom = SecureRandom.getInstance( RANDOM_GENERATOR_ALGORITHM );
    secureRandom.setSeed( seed );
    keyGenerator.init( RANDOM_KEY_SIZE, secureRandom );
    SecretKey secretKey = keyGenerator.generateKey();
    return secretKey.getEncoded();
}

开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:10,代码来源:StringCryptor.java

示例11: generateEncryptionSecret​

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private static byte[] generateEncryptionSecret() {
  try {
    KeyGenerator generator = KeyGenerator.getInstance("AES");
    generator.init(128);

    SecretKey key = generator.generateKey();
    return key.getEncoded();
  } catch (NoSuchAlgorithmException ex) {
    Log.w("keyutil", ex);
    return null;
  }
}

开发者ID:CableIM,项目名称:Cable-Android,代码行数:13,代码来源:MasterSecretUtil.java

示例12: initHmacSHA512Key

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 初始化HmacSHA512密钥
 *
 * @return
 * @throws Exception
 */
public static byte[] initHmacSHA512Key() throws Exception {
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacSHA512");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.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();
    }
    SecretKey secretKey = keyGen.generateKey();
    return secretKey.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");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.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");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}

开发者ID:iBase4J,项目名称:iBase4J-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");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}

开发者ID:iBase4J,项目名称:iBase4J-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 GeneralSecurityException, 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);
        SecretKey key = kg.generateKey();
        Cipher ci1 = Cipher.getInstance(algo + "/" + mo + "/" + pad, p);
        if ("CFB72".equalsIgnoreCase(mo) || "OFB20".equalsIgnoreCase(mo)) {
            throw new RuntimeException(
                    "NoSuchAlgorithmException not throw when mode"
                            + " is CFB72 or OFB20");
        }
        Cipher ci2 = Cipher.getInstance(algo + "/" + mo + "/" + pad, p);
        if ("ECB".equalsIgnoreCase(mo)) {
            ci1.init(Cipher.ENCRYPT_MODE, key);
            ci2.init(Cipher.DECRYPT_MODE, key);
        } else {
            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".equalsIgnoreCase(mo) || "OFB20".equalsIgnoreCase(mo)) {
            out.println("NoSuchAlgorithmException is expected for CFB72 and OFB20");
        } else {
            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);
    SecretKey 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 );
    SecureRandom secure_random = new SecureRandom( Base64.decode( _arg.getBytes() ) );
    key_generator.init( secure_random );
    SecretKey secret_key = key_generator.generateKey();
    return secret_key.getEncoded();
}

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

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

(0)

相关推荐

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

    目录 示例1: EncryptByAes 示例2: main 示例3: wrapperPublicPriviteKeyTest 示例4: initHmacSHA224Key 示例5: run 示例6: initHmacSHA384Key 示例7: wrapperBlowfishKeyTest 示例8: generateMacSha1Key 示例9: ReadWriteSkip 示例10: generateKey 示例11: generateEncryptionSecret​ 示例12: init

  • java加解密RSA使用方法代码示例

    最近为了分析一段请求流,不得不去研究一下RSA加密. 首先,强调一点:密钥的"钥"读"yue",不是"yao",额... 网上关于RSA的原理一抓一大把的,这里只是简单说说我的理解: 1. 两个足够大的互质数p, q: 2. 用于模运算的模 n=p*q: 3. 公钥KU(e, n)中的e满足 1<e< (p-1)(q-1),且与(p-1)(q-1)互质: 4. 密钥KR(d, n)中的d满足  d*e % (p-1)(q-1)= 1,

  • java定时器timer的使用方法代码示例

    1.首先肯定是容器一启动就要启动定时器,所以我们可以选择把定时器写在一个监听器里,容器一启动所以监听器也就跟着启动,然后定时器就可以工作了. 第一步,把自己写的监听器加到web.xml中: 第二步,写一个监听器,实现ServletContextListener接口: 第三步,写一个定时器,继承TimerTask,在复写的run()方法里写具体的业务逻辑. 第四步,在自己的监听器里复写的 public void contextInitialized(ServletContextEvent arg0

  • Java压缩文件工具类ZipUtil使用方法代码示例

    本文实例通过Java的Zip输入输出流实现压缩和解压文件,前一部分代码实现获取文件路径,压缩文件名的更改等,具体如下: package com.utility.zip; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import

  • Java多线程执行处理业务时间太久解决方法代码示例

    背景:在政府开发了一个应用系统,主要功能是让企业填写企业资质信息,然后通过给定的公式,统计这一系列的信息,以得分的形式展示给政府领导查看.目前有1300家企业填报.由于得分是实时显示的,所以导致统计功能很慢. 代码运行流程: 1.查出1300企业信息 2.遍历1300企业信息,ji计算每家企业得分信息.每家预计时间为0.3秒.合计390秒.导致页面请求超时 3.导出(用jxl jar) 解决方案: 由于处理业务的,所以需要能有返回值的线程.用:Callable 直接上代码 1.调用线程的代码 L

  • Java探索之string字符串的应用代码示例

    String类中提供了丰富的用于操作字符串的方法. int indexOf(String str) 该方法用于返回当给定字符串在当前字符串中的位置,若当前字符串不包含给定字符串则返回-1. 重载的方法 int indexOf(String str,int formIndex),从指定下标处(包含)查询子串,返回返回当给定字符串在当前字符串中的位置,若当前字符串不包含给定字符串则返回-1. 用自己的算法实现startsWith和endsWith功能. package com.hz.practice

  • SQL注入原理与解决方法代码示例

    一.什么是sql注入? 1.什么是sql注入呢? 所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令,比如先前的很多影视网站泄露VIP会员密码大多就是通过WEB表单递交查询字符暴出的,这类表单特别容易受到SQL注入式攻击.当应用程序使用输入内容来构造动态sql语句以访问数据库时,会发生sql注入攻击.如果代码使用存储过程,而这些存储过程作为包含未筛选的用户输入的字符串来传递,也会发生sql注入. 黑客通过SQL注入攻击

  • Java中的静态内部类详解及代码示例

    1. 什么是静态内部类 在Java中有静态代码块.静态变量.静态方法,当然也有静态类,但Java中的静态类只能是Java的内部类,也称为静态嵌套类.静态内部类的定义如下: public class OuterClass { static class StaticInnerClass { ... } } 在介绍静态内部类之前,首先要弄清楚静态内部类与Java其它内部类的区别. 2. 内部类 什么是内部类?将一个类的定义放在另一个类的内部,就是内部类.Java的内部类主要分为成员内部类.局部内部类.

  • Spark的广播变量和累加器使用方法代码示例

    一.广播变量和累加器 通常情况下,当向Spark操作(如map,reduce)传递一个函数时,它会在一个远程集群节点上执行,它会使用函数中所有变量的副本.这些变量被复制到所有的机器上,远程机器上并没有被更新的变量会向驱动程序回传.在任务之间使用通用的,支持读写的共享变量是低效的.尽管如此,Spark提供了两种有限类型的共享变量,广播变量和累加器. 1.1 广播变量: 广播变量允许程序员将一个只读的变量缓存在每台机器上,而不用在任务之间传递变量.广播变量可被用于有效地给每个节点一个大输入数据集的副

  • Java编程利用socket多线程访问服务器文件代码示例

    这篇文章将向大家展示Java编程利用socket多线程访问服务器文件代码示例,如果您想先了解Java多线程socket编程的基础知识,可以看下这篇文章:Java多线程编程实现socket通信示例代码. 接下来进入正文,我们看看利用socket多线程访问服务器代码: ServerMain.java package com.ysk.webServer; import java.io.File; import java.io.IOException; import java.net.ServerSoc

随机推荐