简体   繁体   中英

How to resolve AbstractMethod Error in blob encryption?

I want to upload blob into azure blob storage by applying encryption for it. so i have tried to do it using following code:

 File f=new File("/home/prospera-user15/Desktop/test/download.jpeg");

        CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
        CloudBlobClient serviceClient = account.createCloudBlobClient();
        // Container name must be lower case.
        CloudBlobContainer container = serviceClient.getContainerReference("upload1");
        container.createIfNotExists();
        CloudBlockBlob blob = container.getBlockBlobReference("megha");
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(2048);
        final KeyPair wrapKey = keyGen.generateKeyPair();

        RsaKey key = new RsaKey("RSA",wrapKey);
        System.out.println("Uploading the encrypted blob.");
        BlobEncryptionPolicy policy = new BlobEncryptionPolicy(key, null);
        BlobRequestOptions options = new BlobRequestOptions();
        options.setEncryptionPolicy(policy);
        AccessCondition accessCondition = null;
        OperationContext opContext = null;
        try{
            blob.upload(new FileInputStream(f), f.length(), accessCondition, options, opContext);
        }catch (IOException e) {
            System.out.println(e.getMessage());
        }catch (StorageException e) {
            System.out.println(e.getErrorCode());
        }

对于上面的代码,我得到以下异常:

AbstractMethodError implies the definition of some class has incompatibly changed since last compilation

In your case, you might be using old version of an interface implementation which is missing a new interface method and as per stacktrace that might be your RsaKey class/interface.

This exception is thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

Source: https://docs.oracle.com/javase/6/docs/api/java/lang/AbstractMethodError.html

Have you also tried to check if you have authorized your application to use the key or secret per the documentation here ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM