• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BCECPrivateKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey的典型用法代码示例。如果您正苦于以下问题:Java BCECPrivateKey类的具体用法?Java BCECPrivateKey怎么用?Java BCECPrivateKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BCECPrivateKey类属于org.spongycastle.jcajce.provider.asymmetric.ec包,在下文中一共展示了BCECPrivateKey类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doSign

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    if (input.length != 32) {
        throw new IllegalArgumentException("Expected 32 byte input to ECDSA signature, not " + input.length);
    }
    // No decryption of private key required.
    if (privKey == null)
        throw new MissingPrivateKeyException();
    if (privKey instanceof BCECPrivateKey) {
        ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
        ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
        signer.init(true, privKeyParams);
        BigInteger[] components = signer.generateSignature(input);
        return new ECDSASignature(components[0], components[1]).toCanonicalised();
    } else {
        try {
            final Signature ecSig = ECSignatureFactory.getRawInstance(provider);
            ecSig.initSign(privKey);
            ecSig.update(input);
            final byte[] derSignature = ecSig.sign();
            return ECDSASignature.decodeFromDER(derSignature).toCanonicalised();
        } catch (SignatureException | InvalidKeyException ex) {
            throw new RuntimeException("ECKey signing error", ex);
        }
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:ECKey.java


示例2: getPrivKey

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Gets the private key in the form of an integer field element. The public key is derived by performing EC
 * point addition this number of times (i.e. point multiplying).
 *
 *
 * @return  -
 *
 * @throws java.lang.IllegalStateException if the private key bytes are not available.
 */
public BigInteger getPrivKey() {
    if (privKey == null) {
        throw new MissingPrivateKeyException();
    } else if (privKey instanceof BCECPrivateKey) {
        return ((BCECPrivateKey) privKey).getD();
    } else {
        throw new MissingPrivateKeyException();
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:19,代码来源:ECKey.java


示例3: toStringWithPrivate

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Produce a string rendering of the ECKey INCLUDING the private key.
 * Unless you absolutely need the private key it is better for security reasons to just use toString().
 *
 *
 * @return  -
 */
public String toStringWithPrivate() {
    StringBuilder b = new StringBuilder();
    b.append(toString());
    if (privKey != null && privKey instanceof BCECPrivateKey) {
        b.append(" priv:").append(Hex.toHexString(((BCECPrivateKey) privKey).getD().toByteArray()));
    }
    return b.toString();
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:16,代码来源:ECKey.java


示例4: decryptAES

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Decrypt cipher by AES in SIC(also know as CTR) mode
 *
 * @param cipher -proper cipher
 * @return decrypted cipher, equal length to the cipher.
 * @deprecated should not use EC private scalar value as an AES key
 */
public byte[] decryptAES(byte[] cipher){

    if (privKey == null) {
        throw new MissingPrivateKeyException();
    }
    if (!(privKey instanceof BCECPrivateKey)) {
        throw new UnsupportedOperationException("Cannot use the private key as an AES key");
    }


    AESFastEngine engine = new AESFastEngine();
    SICBlockCipher ctrEngine = new SICBlockCipher(engine);

    KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(((BCECPrivateKey) privKey).getD()));
    ParametersWithIV params = new ParametersWithIV(key, new byte[16]);

    ctrEngine.init(false, params);

    int i = 0;
    byte[] out = new byte[cipher.length];
    while(i < cipher.length){
        ctrEngine.processBlock(cipher, i, out, i);
        i += engine.getBlockSize();
        if (cipher.length - i  < engine.getBlockSize())
            break;
    }

    // process left bytes
    if (cipher.length - i > 0){
        byte[] tmpBlock = new byte[16];
        System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i);
        ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0);
        System.arraycopy(tmpBlock, 0, out, i, cipher.length - i);
    }

    return out;
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:45,代码来源:ECKey.java


示例5: getPrivKeyBytes

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Returns a 32 byte array containing the private key, or null if the key is encrypted or public only
 *
 *  @return  -
 */
@Nullable
public byte[] getPrivKeyBytes() {
    if (privKey == null) {
        return null;
    } else if (privKey instanceof BCECPrivateKey) {
        return bigIntegerToBytes(((BCECPrivateKey) privKey).getD(), 32);
    } else {
        return null;
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:16,代码来源:ECKey.java


示例6: getPrivKey

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Gets the private key in the form of an integer field element. The public key is derived by performing EC
 * point addition this number of times (i.e. point multiplying).
 *
 *
 * @return  -
 *
 * @throws IllegalStateException if the private key bytes are not available.
 */
public BigInteger getPrivKey() {
  if (privKey == null) {
    throw new MissingPrivateKeyException();
  } else if (privKey instanceof BCECPrivateKey) {
    return ((BCECPrivateKey) privKey).getD();
  } else {
    throw new MissingPrivateKeyException();
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:ECKey.java


示例7: toStringWithPrivate

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Produce a string rendering of the ECKey INCLUDING the private key.
 * Unless you absolutely need the private key it is better for security reasons to just use toString().
 *
 *
 * @return  -
 */
public String toStringWithPrivate() {
  StringBuilder b = new StringBuilder();
  b.append(toString());
  if (privKey != null && privKey instanceof BCECPrivateKey) {
    b.append(" priv:")
        .append(Hex.toHexString(((BCECPrivateKey) privKey).getD()
            .toByteArray()));
  }
  return b.toString();
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:18,代码来源:ECKey.java


示例8: doSign

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
  if (input.length != 32) {
    throw new IllegalArgumentException(
        "Expected 32 byte input to ECDSA signature, not " + input.length);
  }
  // No decryption of private key required.
  if (privKey == null) throw new MissingPrivateKeyException();
  if (privKey instanceof BCECPrivateKey) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKeyParams =
        new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
    signer.init(true, privKeyParams);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
  } else {
    try {
      Signature ecSig = ECSignatureFactory.getRawInstance(provider);
      ecSig.initSign(privKey);
      ecSig.update(input);
      byte[] derSignature = ecSig.sign();
      return ECDSASignature.decodeFromDER(derSignature)
          .toCanonicalised();
    } catch (SignatureException | InvalidKeyException ex) {
      throw new RuntimeException("ECKey signing error", ex);
    }
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ECKey.java


示例9: decryptAES

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Decrypt cipher by AES in SIC(also know as CTR) mode
 *
 * @param cipher -proper cipher
 * @return decrypted cipher, equal length to the cipher.
 * @deprecated should not use EC private scalar value as an AES key
 */
public byte[] decryptAES(byte[] cipher) {

  if (privKey == null) {
    throw new MissingPrivateKeyException();
  }
  if (!(privKey instanceof BCECPrivateKey)) {
    throw new UnsupportedOperationException("Cannot use the private key as an AES key");
  }

  AESFastEngine engine = new AESFastEngine();
  SICBlockCipher ctrEngine = new SICBlockCipher(engine);

  KeyParameter key =
      new KeyParameter(BigIntegers.asUnsignedByteArray(((BCECPrivateKey) privKey).getD()));
  ParametersWithIV params = new ParametersWithIV(key, new byte[16]);

  ctrEngine.init(false, params);

  int i = 0;
  byte[] out = new byte[cipher.length];
  while (i < cipher.length) {
    ctrEngine.processBlock(cipher, i, out, i);
    i += engine.getBlockSize();
    if (cipher.length - i < engine.getBlockSize()) break;
  }

  // process left bytes
  if (cipher.length - i > 0) {
    byte[] tmpBlock = new byte[16];
    System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i);
    ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0);
    System.arraycopy(tmpBlock, 0, out, i, cipher.length - i);
  }

  return out;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:44,代码来源:ECKey.java


示例10: getPrivKeyBytes

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Returns a 32 byte array containing the private key, or null if the key is encrypted or public only
 *
 *  @return  -
 */
@Nullable public byte[] getPrivKeyBytes() {
  if (privKey == null) {
    return null;
  } else if (privKey instanceof BCECPrivateKey) {
    return bigIntegerToBytes(((BCECPrivateKey) privKey).getD(), 32);
  } else {
    return null;
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:15,代码来源:ECKey.java


示例11: getPrivKey

import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; //导入依赖的package包/类
/**
 * Gets the private key in the form of an integer field element. The public key is derived by performing EC
 * point addition this number of times (i.e. point multiplying).
 *
 *
 * @return  -
 *
 * @throws IllegalStateException if the private key bytes are not available.
 */
public BigInteger getPrivKey() {
    if (privKey == null) {
        throw new MissingPrivateKeyException();
    } else if (privKey instanceof BCECPrivateKey) {
        return ((BCECPrivateKey) privKey).getD();
    } else {
        throw new MissingPrivateKeyException();
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:ECKey.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HiveCharObjectInspector类代码示例发布时间:2022-05-22
下一篇:
Java AbstractUdfStreamOperator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap