当前位置: 首页>>代码示例>>Java>>正文


Java InvalidKeyException类代码示例

本文整理汇总了Java中com.sun.spot.security.InvalidKeyException的典型用法代码示例。如果您正苦于以下问题:Java InvalidKeyException类的具体用法?Java InvalidKeyException怎么用?Java InvalidKeyException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InvalidKeyException类属于com.sun.spot.security包,在下文中一共展示了InvalidKeyException类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serializeECPublicKey

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/** Serializes ECPublicKeys into the following format
 */
private static byte[] serializeECPublicKey(ECPublicKeyImpl key,
        int headerSize) throws InvalidKeyException, IOException {
    /* To store the EC Key we actually need
     * 1 + 2 * (key.getSize() + 7) >>3 bytes
     * according to the implementation of key.getW.
     * There should be a method for getting this number but there
     * doesn't seem to be.
     */
    int wLen = 1 + 2 * ((key.getSize() + 7) >>> 3);
    /* [curveId][wLength][w] */
    /* allocate space for the header, curve id, w length, w */
    byte[] rawKey = new byte[headerSize + 1 + 1 + wLen];
    int strAddr = headerSize;
    rawKey[strAddr] = (byte)key.getCurve();
    strAddr ++;
    rawKey[strAddr] = (byte)wLen;
    strAddr ++;
    if (key.getW(rawKey, strAddr) == 0) {
        throw new IOException("Serialization of EC Key failed");
    }
    return rawKey;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:25,代码来源:KeySerializer.java

示例2: engineInit

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
    * Initializes this cipher with a key and a set of algorithm
    * parameters.
    *
    * @param opMode the operation mode of this cipher
    * @param key the encryption key
    * @param params the algorithm parameters
    *
    * @exception java.security.InvalidKeyException if the given key
    * is inappropriate for initializing this cipher
    * @exception java.security.InvalidAlgorithmParameterException
    * if the given algorithm parameters are inappropriate for this cipher
    * @exception IllegalArgumentException if opMode is incorrect
    */
   protected void engineInit(int opMode, Key key, AlgorithmParameterSpec params)
           throws InvalidKeyException, InvalidAlgorithmParameterException {

if (params!=null) 
    throw new InvalidAlgorithmParameterException(RSA_ALGORITHM_NAME+" does not support AlgorithmParameterSpec. Must be null."); 

       if (!(key instanceof RSAKey)) {
           throw new InvalidKeyException();
       }

       if (opMode != Cipher.DECRYPT_MODE && opMode != Cipher.ENCRYPT_MODE) {
           throw new IllegalArgumentException("Wrong operation mode");
       }

       mode = opMode;
       ckey = (RSAKey)key;

       if (ckey.getModulusLen() == 0) {
           throw new InvalidKeyException();
       }

       messageToSign = new byte[ckey.getModulusLen()];
       bytesInMessage = 0;
   }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:39,代码来源:RSA.java

示例3: genKeyPair

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
public static void genKeyPair(ECPublicKeyImpl publicKey, ECPrivateKeyImpl privateKey)
        throws InvalidKeyException, NoSuchAlgorithmException {
    
    // both keys must be initialized with the same curve
    if (publicKey.curveid != privateKey.curveid) {
        throw new InvalidKeyException();
    }
    ECCurve curve = privateKey.curve;
    FFA ffa = curve.getOrder().getFFA();
    publicKey.clearKey();
    privateKey.clearKey();
    
    // generate a random number in the range: 0 < x < field.prime
    SecureRandom random = SecureRandom.getInstance(SecureRandom.ALG_SECURE_RANDOM);
    int lastBit = curve.getOrder().getBitSize() - 1;
    byte[] priv = new byte[(lastBit >> 3) + 1];
    
    do {
        random.generateData(priv, 0, priv.length);
        priv[0] &= (byte)mask[lastBit % 8];
        // now 'priv' contains our random number, where bit positions
        // beginning at the bit length of the prime are masked out.
        ffa.from(privateKey.keyData, priv, 0, priv.length);
        // loop until the generated random number is in the desired range.
        // the worst case probability that this loops is 50%
    } while ((ffa.cmp(privateKey.keyData, curve.getN()) >= 0) ||
             (ffa.is(privateKey.keyData, 0)));
    
    // generate the public key
    curve.copy(publicKey.keyData, curve.getGenerator());
    curve.multiply(publicKey.keyData, privateKey.keyData);
    privateKey.keyLength = (ffa.bitLength(privateKey.keyData) + 7) >>> 3;        
    
    // both keys are initialized by now
    privateKey.initOk = true;
    publicKey.initOk = true;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:38,代码来源:ECKeyImpl.java

示例4: initSign

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
public void initSign(PrivateKey theKey) throws InvalidKeyException {
try {
               signKey = (ECPrivateKeyImpl)theKey;
               verifyKey = null;
       } catch (ClassCastException e) {
          throw new InvalidKeyException();
       }
       key = (ECKeyImpl)theKey;

       // Insert code here to add support for F2^m. The rest of this class
       // should be independent of the of the curve type.

   }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:14,代码来源:ECDSASignature.java

示例5: initVerify

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
public void initVerify(PublicKey theKey) throws InvalidKeyException {
try {
   
               verifyKey = (ECPublicKeyImpl)theKey;
               signKey = null;
       } catch (ClassCastException e) {
           throw new InvalidKeyException();
       }
       key = (ECKeyImpl)theKey;

       // Insert code here to add support for F2^m. The rest of this class
       // should be independent of the of the curve type.

   }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:15,代码来源:ECDSASignature.java

示例6: getW

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
public int getW(byte[] buffer, int offset) throws InvalidKeyException {
    if (!initOk) {
        throw new InvalidKeyException("Not initialized");
        
    }
    return curve.encodePoint(keyData, buffer, offset);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:8,代码来源:ECPublicKeyImpl.java

示例7: initVerify

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
 * Initializes the <CODE>RSASig</CODE> object with the appropriate
 * <CODE>Key</CODE> for signature verification.
 * 
 * @param theKey the key object to use for verification
 *
 * @exception InvalidKeyException if the key type is inconsistent 
 * with the mode or signature implementation.
 */
public void initVerify(PublicKey theKey) throws InvalidKeyException {
    if (!(theKey instanceof RSAPublicKey)) {
        throw new InvalidKeyException();
    }

    c.init(Cipher.DECRYPT_MODE, theKey);

    k = (RSAKey)theKey;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:19,代码来源:RSASig.java

示例8: initSign

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
 * Initializes the <CODE>RSASig</CODE> object with the appropriate
 * <CODE>Key</CODE> for signature creation.
 * 
 * @param theKey the key object to use for signing
 *
 * @exception InvalidKeyException if the key type is inconsistent 
 * with the mode or signature implementation.
 */
public void initSign(PrivateKey theKey) throws InvalidKeyException {
    if (!(theKey instanceof RSAPrivateKey)) {
        throw new InvalidKeyException();
    }

    c.init(Cipher.ENCRYPT_MODE, theKey);

    k = (RSAKey)theKey;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:19,代码来源:RSASig.java

示例9: engineInit

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException {


    initOk = false;
    if (!(key instanceof SecretKeySpec)) {
        throw new InvalidKeyException("Key is not of required type SecretKey.");
    }
    if ((opmode != Cipher.ENCRYPT_MODE) && (opmode != Cipher.DECRYPT_MODE)) {
        throw new IllegalArgumentException("Unsupported mode.");
    }
	
    if (params instanceof IvParameterSpec) {
        ivParameter=(IvParameterSpec)params;
        if (!modeCBC) {
    	throw new InvalidAlgorithmParameterException("AlgorithmParameterSpec must be null for "+ALG1+" in ECB mode.");
        }
    } else if (params!=null) {
        throw new InvalidAlgorithmParameterException("AlgorithmParameterSpec params has to be null or IvParamater. Is: "+params.getClass().getName());
    }
    
    if (modeCBC) {
        IV = new int[4];
        if (ivParameter == null) {
            clearIV();
        } else {
    	unpackBlock(ivParameter.getIV(), 0, IV); 
        }
    }
    
    mode = opmode;
    this.key = (SecretKeySpec)key;

    generateWorkingKey(this.key.getEncoded(), (mode == Cipher.ENCRYPT_MODE)); 
    initOk = true;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:37,代码来源:Alg1.java

示例10: engineInit

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
protected abstract void engineInit(int opmode, Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException;
 
开发者ID:tomatsu,项目名称:squawk,代码行数:3,代码来源:CipherSpi.java

示例11: engineInit

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
protected void engineInit(int theMode, Key theKey, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params!=null) 
    throw new InvalidAlgorithmParameterException(ALG2+" does not support AlgorithmParameterSpec. Must be null"); 
if (!(theKey instanceof SecretKeySpec)) {
    throw new InvalidKeyException();
}
 if   ((theMode != Cipher.ENCRYPT_MODE) && 
     (theMode != Cipher.DECRYPT_MODE)) {
    throw new InvalidAlgorithmParameterException();	    
    //CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
}
       /*if (!theKey.isInitialized()) {
    CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY);
       }*/

this.mode = theMode;
       this.key = theKey;
       
byte[] K = ((SecretKeySpec)theKey).getEncoded();
       int kLen = ((SecretKeySpec)theKey).getEncoded().length;

/* Initialize S */
for (int i = 0; i < 256; i++) {
           S[i] = (byte) i;
       }

int j = 0;
       int k = 0;
byte temp;
for (int i = 0; i < 256; i++) {
    j = (j + ((S[i] + K[k]) & 0xff)) & 0xff;
    temp = S[i];
    S[i] = S[j];
    S[j] = temp;
           if (++k >= kLen) k = 0;
}
       
       jj = ii = 0;
       
       initOk = true;
       needsReset = false;
   }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:43,代码来源:Alg2.java

示例12: engineDoFinal

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
    * Process the final data record.
    * 
    * @param inBuf input buffer of data 
    * @param inOff offset in the provided input buffer
    * @param inLen length of data to be processed
    * @param outBuf output buffer of data 
    * @param outOff offset in the provided output buffer
    * @return number of bytes copied to output buffer
    *
    * @exception IllegalStateException if this cipher is in a wrong state
    * (e.g., has not been initialized)
    * @exception IllegalBlockSizeException if this cipher is a block cipher,
    * no padding has been requested (only in encryption mode), and the total
    * input length of the data processed by this cipher is not a multiple of
    * block size
    * @exception ShortBufferException if the given output buffer is too small
    * to hold the result
    * @exception BadPaddingException if this cipher is in decryption mode,
    * and (un)padding has been requested, but the decrypted data is not
    * bounded by the appropriate padding bytes
    * @exception IllegalArgumentException if input is greater than the
    *            cipher with the given key can handle, or the output
    *            parameters are invalid
    */
   public int engineDoFinal(byte[] inBuf, int inOff, int inLen, 
                      byte[] outBuf, int outOff)
       throws IllegalStateException, ShortBufferException,
              IllegalBlockSizeException, BadPaddingException {

       addToMessage(inBuf, inOff, inLen);

       if (outBuf == null || outOff < 0) {
           throw new IllegalArgumentException("output out of bounds");
       }

       int val = performRsa(messageToSign, 0, bytesInMessage, outBuf, outOff);

       try {
           engineInit(mode, ckey,null);
       } catch (InvalidKeyException ike) {
           // Ignore, nothing to do
       } catch (InvalidAlgorithmParameterException e) {
    // Ignore, nothing to do	    
}

       return val;
   }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:49,代码来源:RSA.java

示例13: init

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
 * Initializes this cipher with a key.
 *
 * <p>The cipher is initialized for one of the following operations:
 * encryption, decryption,  depending
 * on the value of <code>opmode</code>.
 *
 * <p>If this cipher requires any algorithm parameters that cannot be
 * derived from the given <code>key</code>, the underlying cipher
 * implementation is supposed to generate the required parameters itself
 * (using provider-specific default or random values) if it is being
 * initialized for encryption, and raise an
 * <code>InvalidKeyException</code> if it is being
 * initialized for decryption.
 *
 * <p>Note that when a Cipher object is initialized, it loses all
 * previously-acquired state. In other words, initializing a Cipher is
 * equivalent to creating a new instance of that Cipher and initializing
 * it.
 *
 * @param opmode the operation mode of this cipher (this is one of
 * the following:
 * <code>ENCRYPT_MODE</code> or <code>DECRYPT_MODE</code>)
 * @param key the key
 *
 * @exception InvalidKeyException if the given key is inappropriate for
 * initializing this cipher, or if this cipher is being initialized for
 * decryption and requires algorithm parameters that cannot be
 * determined from the given key, or if the given key has a keysize that
 * exceeds the maximum allowable keysize.
 */
public final void init(int opmode, Key key) throws InvalidKeyException {
    try {
        init(opmode, key, null);
    } catch (InvalidAlgorithmParameterException e) {
        throw new InvalidKeyException();
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:39,代码来源:Cipher.java

示例14: initVerify

import com.sun.spot.security.InvalidKeyException; //导入依赖的package包/类
/**
 * Initializes the <CODE>RSASig</CODE> object with the appropriate
 * <CODE>Key</CODE> for signature verification.
 * 
 * @param theKey the key object to use for verification
 *
 * @exception InvalidKeyException if the key type is inconsistent 
 * with the mode or signature implementation.
 */
public void initVerify(PublicKey theKey) throws InvalidKeyException {
    rsaSig.initVerify(theKey);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:13,代码来源:RsaMd5Sig.java


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